114 lines
2.1 KiB
Python
114 lines
2.1 KiB
Python
|
######Exercice 1 ######
|
||
|
from math import*
|
||
|
##Question 1:##
|
||
|
|
||
|
def multiplesde7(n):
|
||
|
l=[]
|
||
|
for i in range(n):
|
||
|
if i%7==0:
|
||
|
l+=[i]
|
||
|
return l
|
||
|
|
||
|
|
||
|
print(multiplesde7(100))
|
||
|
|
||
|
|
||
|
##Question 2##
|
||
|
|
||
|
Un nombre (n) est premier si aucun nombre inferieur a sqrt(n) en divise (n).
|
||
|
On vérifie ici ce théoreme en testant sucessivement la divisibilité des (i) par (n) avec (i) variant de 2 a sqrt(n)
|
||
|
|
||
|
##Question 3##
|
||
|
|
||
|
def isprime(n):
|
||
|
s=int(sqrt(n))
|
||
|
t=True
|
||
|
i=2
|
||
|
while i<=s and t==True:
|
||
|
if n% i==0:
|
||
|
t=False
|
||
|
i+=1
|
||
|
return(t)
|
||
|
|
||
|
def listepremier(n):
|
||
|
l=[]
|
||
|
for i in range(2,n+1):
|
||
|
if isprime(i):
|
||
|
l+=[i]
|
||
|
return l
|
||
|
|
||
|
##Question 4##
|
||
|
def premier():
|
||
|
p=[]
|
||
|
n=2
|
||
|
while len(p)!=100:
|
||
|
if isprime(n):
|
||
|
p+=[n]
|
||
|
n+=1
|
||
|
return p
|
||
|
|
||
|
##Question 5##
|
||
|
|
||
|
def jumeaux():
|
||
|
l=[]
|
||
|
for i in range(2,3000):
|
||
|
if isprime(i) and isprime(i+2):
|
||
|
l+=[(i,i+2)]
|
||
|
return l
|
||
|
|
||
|
##Question 6#
|
||
|
|
||
|
n=0
|
||
|
while 1<2:
|
||
|
a=2**(2**n) +1
|
||
|
if isprime(a) == False:
|
||
|
print(False, n)
|
||
|
break
|
||
|
n+=1
|
||
|
## Question 7 BONUS (à traiter plus tard) ##
|
||
|
|
||
|
######Exercice 2######
|
||
|
|
||
|
##Question 1##
|
||
|
a=1
|
||
|
print(a)
|
||
|
for i in range(100):
|
||
|
b=(1/2)*(a+(2/a))
|
||
|
print(b)
|
||
|
a=b
|
||
|
|
||
|
##Question 2##
|
||
|
a=1
|
||
|
print(a)
|
||
|
for i in range(10):
|
||
|
b=(1/2)*(a+(2/a))
|
||
|
print((b)**2 - 2)
|
||
|
a=b
|
||
|
# les valeurs tendent très rapidement vers 0 car sqrt(2)**2 - 2 = 0
|
||
|
|
||
|
##Question 3#
|
||
|
a=1
|
||
|
l=[1]
|
||
|
for i in range(10):
|
||
|
b=(1/2)*(a+(2/a))
|
||
|
l+=[b**2-2]
|
||
|
a=b
|
||
|
i=0
|
||
|
while 1<2:
|
||
|
if l[i]<0.00002
|
||
|
print(i)
|
||
|
break
|
||
|
i+=1
|
||
|
# On cherche a encadrer |Un**2 -2|
|
||
|
#Sachant que la condition d'arrêt de départ est :
|
||
|
#|Un-sqrt(2)|<10**-5
|
||
|
#Or x->sqrt(x) est 1/2 lispsiptienne => |f(y)-f(x)|<1/2 |x-y| On pose x=Un**2 et y=2=(sqrt(2))**2
|
||
|
#Ainsi, on a |Un -sqrt(2)|<1/2|Un**2-2|
|
||
|
#Or on souhaite avoir |Un -sqrt(2)|<10**-5. Une proposition plus forte consiste à dire:
|
||
|
# |Un-sqrt(2)|<1/2|Un**2-2|<10**-5
|
||
|
#<=> 2*|Un-sqrt(2)|<|Un**2-2|<2*10**-5
|
||
|
#D'ou la condition d'arrêt : |Un**2-2|<2*10**-5
|
||
|
|
||
|
|
||
|
|