-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem3.py
64 lines (49 loc) · 894 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def pfacts(n, m):
if m == 1:
print 1
elif n % m == 0:
print n/m
pfacts(m, m/2)
else:
pfacts(n, m-1)
def prime(n,m):
if m == 1:
return n
elif n % m == 0:
return prime(m, m/2)
else:
return prime(n, m-1)
def another(n, m):
if m > n/2:
return n
elif n % m == 0:
return another(n/m, m)
else:
return another(n, m+1)
def another1(n, i):
while( i <= n/2):
if n % i == 0:
return another1(n/i, i)
i = i+1
return n
def iterative( n ):
i = n/2
while(i>0):
if isPrime(i) and (n%i == 0):
return(i)
i = i-1
return n
def isPrime( n ):
if n < 2:
return False
else:
for i in range(2, n/2):
if n % i == 0:
return False
return True
# pfacts(130,130/2)
# print iterative(600851475143)
# print another(35,2)
print another1(600851475143,2)
# print prime(13195, 13195/2)
# print prime(13195, 13195/2)