-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem3.py
37 lines (34 loc) · 827 Bytes
/
problem3.py
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
import math
import time
def isItPrime(num):
root = int(math.floor(math.sqrt(num)))
for i in range(3,root,2):
if(num%i==0):
return False
return True
def checkPower(num,i):
j=1
while(num%(math.pow(i,j)) == 0):
j+=1
return (j-1)
ret = 1
num=600851475143
i=3
timer = time.clock()
while(i<int(math.floor(num/2))):
#timer = time.clock()
boo = isItPrime(i)
#timer = time.clock()-timer
#print "time taken for isItPrime(" + str(i) + "): " + str(timer)
#print "checking " + str(i)
if(num%i == 0 and boo):
n=checkPower(num,i)
#print "the prime power " + str(i) + "^" + str(n) + " is a factor"
num=num/(math.pow(i,n))
ret = i
i+=2
if(isItPrime(num) and num>ret):
ret = num
timer=time.clock()-timer
print timer
print ret