python program to go through trees of prime numbers

This commit is contained in:
Robin P. Clark 2015-07-16 16:28:41 +01:00
parent ec7d0edb71
commit 4ae48a5649

40
papers/fermat/p.py Normal file
View 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);