Hi you all! This is my very first post in the forum :P I'm sorry for my english, that's because I'm from Portugal.
Anyway, I have this work assignment I need to do for school but was in need of your help with the last part of it.
As in the tittle, I need a function that factorizes a given number n into his prime factors. Something like:
"Write a number: 600
600 = 2^3 * 3^1 * 5^2 "
I need to do that funtion using only ifs, whiles, etc. well... the most basics you can imagine. So I can't use any arrays or for cicles, wich I think would make it easier...
I did a little search in the forum and I found this "code" written by a user in other post:
I think something like this is what I need, but a need to understand it, I need to add the part where it prints "2^3 * 3^4......" and basically I need to code it.Code:n = number entered by user sqrt_n = sqrt(n) i = 2 while n > 1 and i <= sqrt_n if n is divisible by i add i to list of prime factors count = 1 n = n / i while n is divisible by i increment count n = n / i add count to list of prime factor counts increment i if n > 1 add n to list of prime factors add 1 to list of prime factor counts
If you could help with this it would be great.
Thank you in advance.



LinkBack URL
About LinkBacks



