Advertisement
Blogdemaths

Blogdemaths - Factorisation des nombres de Fermat

Feb 6th, 2016
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. ####################################################
  2. #
  3. # Blogdemaths - Factorisation des nombres de Fermat
  4. #
  5. # https://blogdemaths.wordpress.com/2016/02/07/nombres-de-fermat-1ere-partie-comment-euler-a-factorise-f5/
  6. #
  7. ####################################################
  8.  
  9. def FermatLucas(n):
  10.     """ Renvoie le plus petit diviseur premier du nombre de Fermat 2^(2^n)+1 """
  11.    
  12.     #Nombre de Fermat
  13.     F=2**(2**n)+1
  14.  
  15.     #Diviseur premier potentiel
  16.     k=1
  17.     deuxnplusdeux = 2**(n+2)
  18.     p= deuxnplusdeux+1 #p=2^(n+2)+1 au départ
  19.  
  20.     while not(F%p==0):
  21.  
  22.         p+=deuxnplusdeux
  23.        
  24.     k = (p-1)//deuxnplusdeux
  25.     print(("F{} est divisible par "+str(p)+" = {} x 2^"+str(n+2)+" + 1").format(n,k))
  26.     #print("On a la factorisation:\nF{} = {} x {}".format(n,p,F//p))
  27.    
  28.     return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement