goldbach.py

Created by elodie-gamot

Created on June 30, 2022

593 Bytes

Tester la conjecture de Goldbach


from math import *

def nombre_premier(n):
  if n>1:
    for k in range(2,sqrt(n)+1):
      if k<n and n%k==0:
        #need k<n if n=2
        return False
    return True

def liste(n):
  return [k for k in range(1,n+1) if nombre_premier(k)==True]
  
def goldbach(n):
  #solution=0
  if n<3:
    return "C'est inferieur a trois"
  elif n%2!=0:
    return "C'est impair"
  else:
    for i in range(len(liste(n))):
      for j in range(i,len(liste(n))):
        if liste(n)[i]+liste(n)[j]==n:
          #solution+=1
          print(liste(n)[i],liste(n)[j])
  #return solution  

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.