
|
./Ruby/Prime Factoring
#PRIME FACTOR
num = 3954867435
primes = []
print "\nPrime Factor of #{num}: "
i = 2
numlimit = Math.sqrt(num).round
while(i <= numlimit)
while(num > 1 && num/(i.to_f) == (num/(i.to_f)).round.to_f)
primes << i
num = num/i
numlimit = Math.sqrt(num).round
end
i += 1
end
primes << num
primes.delete(1)
puts primes.join('*')
OUTPUT:
Prime Factor of 3954867435: 3*3*5*547*160669 |
| Copyright © 2005-2006, Joby Bednar. All Rights Reserved Nothing may be reused without my approval. |
You: 38.107.191.98 Now: 9/8/2010 5:25:44 AM |