Advertisement
tpaper

Untitled

Sep 20th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. c=2
  2. primi=[2]
  3.  
  4. def getcomp(num):
  5.   out = []
  6.   num = str(num)
  7.   ln = len(num)
  8.   for ran in range(1,ln):
  9.     k = int(num[0:ran])
  10.     if isprime(k):
  11.       out.append(k)
  12.   for ran in range(1,ln):
  13.     k = int(num[ran:ln])
  14.     if isprime(k):
  15.       out.append(k)
  16.   return list(set(out))
  17.  
  18. def acceptable(seed,elenco):
  19.   for k in elenco:
  20.     if not (isprime(int(str(seed)+str(k))) and isprime(int(str(k)+str(seed)))):
  21.       return False
  22.   return True
  23.  
  24. def isprime(num):
  25.   if num<c:
  26.     return (num in primi)
  27.   for t in range(2,int(num**0.5)+1):
  28.     if num%t==0:
  29.       return False
  30.   return True
  31.  
  32. def nextprime(finoa):
  33.   global c,primi
  34.   while c<(finoa+1)*10:
  35.     p=True
  36.     for t in primi:
  37.       if t>(c)**0.5+1:
  38.     break
  39.       if c%t==0:
  40.     p = False
  41.     break
  42.     if p:
  43.       primi.append(c)
  44.     c=c+1
  45.    
  46. def getprime(finoa):
  47.   primi = [2]
  48.   c=2
  49.   while c<(finoa+1)*10:
  50.     p=True
  51.     for t in primi:
  52.       if t>(c)**0.5+1:
  53.     break
  54.       if c%t==0:
  55.     p = False
  56.     break
  57.     if p:
  58.       primi.append(c)
  59.     c=c+1
  60.   return primi
  61.    
  62. def nextprimeb():
  63.   global c,primi
  64.   z = len(primi)
  65.   while z==len(primi):
  66.     p=True
  67.     for t in primi:
  68.       if t>(c)**0.5+1:
  69.     break
  70.       if c%t==0:
  71.     p = False
  72.     break
  73.     if p:
  74.       primi.append(c)
  75.     c=c+1
  76.    
  77. #nextprime(3)
  78. #print getcomp(36733)
  79. def getother(clist):
  80.   z=0
  81.   while not acceptable(z,clist):
  82.     if z>100000:
  83.       return clist
  84.     z = primi[-1]
  85.     #print z
  86.     nextprimeb()
  87.   return getother(clist+[z])
  88.  
  89. l = getprime(20)
  90.  
  91. print 'fuori>',getother([3])
  92. for cur in [1,2]:
  93.   print 'dentro>',getother([3])
  94.   #print cur,
  95.   #print len(getother([3]))
  96.   #  print getother([cur]),sum(getother([cur]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement