python program to go through trees of prime numbers
This commit is contained in:
parent
ec7d0edb71
commit
4ae48a5649
40
papers/fermat/p.py
Normal file
40
papers/fermat/p.py
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# find prime factors of a number
|
||||
def primefactors(x):
|
||||
factorlist=[]
|
||||
loop=2
|
||||
while loop<=x:
|
||||
if x%loop==0:
|
||||
x/=loop
|
||||
factorlist.append(loop)
|
||||
else:
|
||||
loop+=1
|
||||
return factorlist
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def tree(a,b):
|
||||
print "tree called with ",a,b;
|
||||
pf = primefactors(a+b);
|
||||
print "prime factors of adition" , pf;
|
||||
if len(pf) > 1:
|
||||
for p in pf:
|
||||
p;
|
||||
aa = a * p;
|
||||
print "a side cfp added"
|
||||
pf2 = tree(aa,b);
|
||||
bb = b * p;
|
||||
print "b side cfp added"
|
||||
pf2 = tree(a,bb);
|
||||
else:
|
||||
print " |>------------> single prime stopping tree branch iteration", pf
|
||||
|
||||
|
||||
tree(51,27);
|
||||
print "prime factors of 2468 are ", primefactors(2468);
|
Loading…
Reference in New Issue
Block a user