Advertisement
Blogdemaths

Blogdemaths - L'autre conjecture de Goldbach

Aug 28th, 2015
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #####################################################
  2. # http://blogdemaths.wordpress.com
  3. #
  4. # L'autre conjecture de Goldbach
  5. # https://blogdemaths.wordpress.com/2015/08/28/lautre-conjecture-de-goldbach/
  6. #
  7. # Ce programme renvoie le plus petit entier impair
  8. # qui ne peut pas s'écrire sous la forme : p + 2a^2
  9. # où p est 1 ou est un nombre premier
  10. # et a est un entier.
  11. ######################################################
  12.  
  13. import math
  14.  
  15. def est_premier(p):
  16.     if p==0 or p==1:
  17.         return False
  18.     elif p==2:
  19.         return True
  20.     else:
  21.         maxi = int(math.sqrt(p))
  22.  
  23.         for k in range(2,maxi+1):
  24.             if p%k==0:
  25.                 return False
  26.            
  27.         return True
  28.    
  29.  
  30. def autre_Goldbach(n):
  31.     maxi = int(math.sqrt(n/2))
  32.  
  33.     for a in range(0,maxi+1):
  34.         p=n-(2*(a**2))
  35.         if p==1 or est_premier(p):
  36.             #print("{} = {} + 2 x {} ^ 2".format(n,p,a))
  37.             return True
  38.     return False
  39.  
  40.                  
  41.    
  42. if __name__=="__main__":
  43.     n=1
  44.     while autre_Goldbach(n):
  45.         n+=2
  46.  
  47.     print("Le nombre {} met en défaut la conjecture.".format(n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement