Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # blogdemaths.wordpress.com - "En 2014, point de carré"
- #
- # Le programme suivant tire au hasard 100 nombres entre 1 et 1 000 000 et teste si chacun est sans facteur carré
- # puis renvoie un intervalle de confiance sur la proportion du nombre d'entiers sans facteur carré compris entre
- # 1 et 1 000 000.
- import math
- import urllib.request
- def sans_facteur_carre(n):
- depart=2
- while n>1:
- d=int(math.sqrt(n))
- j=depart
- while not n%j==0:
- j+=1
- if n%(j**2)==0:
- return False
- else:
- n=n//j
- depart=j+1
- return True
- N=1000000
- taille_echantillon = 100
- siterandom = "http://www.random.org/integers/?num="+str(taille_echantillon)+"&min=1&max="+str(N)+"&col=1&base=10&format=plain&rnd=new"
- echantillon = urllib.request.urlopen(siterandom).read().decode('utf-8')
- compteur=0
- for n in echantillon.split():
- if sans_facteur_carre(int(n)):
- compteur+=1
- frequence= compteur/taille_echantillon
- print("Sur un echantillon de ", taille_echantillon,"nombres pris au hasard entre 1 et "+str(N)+", il y a",round(frequence*100,3),"% des nombres qui sont sans facteur carré.")
- confiance = 0.95
- t= 1.96
- mini= frequence - t * math.sqrt((frequence*(1-frequence))/taille_echantillon)
- maxi= frequence + t * math.sqrt((frequence*(1-frequence))/taille_echantillon)
- print("Un intervalle de confiance au niveau de confiance de",confiance*100,"% est [",round(mini,3),";",round(maxi,3),"]")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement