My PC was not slow, but with the below simple algorithm, my PC needs 1s.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
def primeFactors(n):
factors = []
p = 2
while n > 1 :
if n % p = = 0 :
factors + = [ p ]
print (p, end = "," )
n = n / / p
else :
p = p + 1
print ()
return factors
def multiply(factors):
n = 1
for f in factors:
n * = f
return n
n = 3226064841928059523397979569946338218262205752503893243027824368891777440698556243004554463193287418911567727801430320528268997104967216533294045386641450118600488493439275991430590233442080228938358171935320314414150553379009317199377287861726656707087781474818468157561232944906242003584398983171485589345483705115268063332800
print ( "number" , n)
print ( "---" )
factors = primeFactors(n)
print ( "---" )
m = multiply(factors)
print ( "result" , m)
print ( "---" )
if n = = m:
print ( "OK" )
else :
print ( "ERROR" )
|
Output:
number 3226064841928059523397979569946338218262205752503893243027824368891777440698556243004554463193287418911567727801430320528268997104967216533294045386641450118600488493439275991430590233442080228938358171935320314414150553379009317199377287861726656707087781474818468157561232944906242003584398983171485589345483705115268063332800
---
2,2,2,2,2,2,3,3,3,3,5,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,
---
result 3226064841928059523397979569946338218262205752503893243027824368891777440698556243004554463193287418911567727801430320528268997104967216533294045386641450118600488493439275991430590233442080228938358171935320314414150553379009317199377287861726656707087781474818468157561232944906242003584398983171485589345483705115268063332800
---
OK