Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 10th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def es_divisible(x,y):
  2.     a = x%y==0
  3.     return a
  4.  
  5. def es_primo(x):
  6.     if x==2:
  7.         a=True
  8.         return a
  9.     elif x==1:
  10.         a=False
  11.         return a
  12.     else:
  13.         for i in range(2,x):
  14.             if es_divisible(x,i)==True:
  15.                 a=False
  16.                 break
  17.             else:
  18.                 a=True
  19.    
  20.         return a
  21.  
  22. def i_esimo_primo(i):
  23.     m=2
  24.     cont=0
  25.     while i!=cont:
  26.         if es_primo(m)==True:
  27.             cont+=1
  28.         m+=1
  29.     return (m-1)
  30.            
  31. def primeros_hasta(m):
  32.     a=[]
  33.     conteo=0
  34.     while m!=conteo:
  35.         a.append(i_esimo_primo(conteo+1))
  36.         conteo+=1
  37.     return a
  38.  
  39. def primos_hasta(m):
  40.     a=[2]
  41.     conteo=1
  42.     while a[-1]<m:
  43.         a.append(i_esimo_primo(conteo+1))
  44.         conteo+=1
  45.     return a
  46.    
  47.    
  48.        
  49.        
  50.  
  51. x=int (raw_input("Ingrese valor x: "))
  52. conteo=1
  53. conteo2=1
  54. while conteo<=x:
  55.     while es_primo((2**(i_esimo_primo(conteo2))-1)==True:
  56.                    
  57.         print(2**(i_esimo_primo(conteo))-1
  58.         conteo2 +=1
  59.     conteo+=1