Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def primes(x):
- """Calcule la liste des premiers inférieurs à x."""
- P = []
- for n in range(2,x):
- isprime = True
- for p in P:
- if n % p == 0:
- isprime = False
- if isprime:
- P.append(n)
- return(P)
- def test(n, p):
- """Teste si n mod p est premier."""
- b = (n % p) in primes(p)
- return(b)
- def enigme(bmin, bmax, mods):
- """Résoud l'énigme pour des valeurs entre bmin et bmax,
- mods listant les dividendes dans le calcul des restes."""
- sol = []
- for n in range(bmin, bmax):
- b = True
- for p in mods:
- b = b and test(n, p)
- if b:
- sol.append(n)
- return(sol)
- if __name__ == '__main__':
- r = "La solution est {}. {} un nombre premier."
- s = enigme(10, 1000, [5, 7, 11, 13, 17, 19, 23])[0]
- if s in primes(s+1):
- c = "C'est"
- else:
- c = "Ce n'est pas"
- print(r.format(s, c))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement