• Aucun résultat trouvé

Nombres premiers

N/A
N/A
Protected

Academic year: 2022

Partager "Nombres premiers"

Copied!
2
0
0

Texte intégral

(1)

NOMBRES

G RIP

CASIO

TOUTES CALCULATRICES

CASIO

Un nombre étant donné, dire s’il est premier ou non.

On pourrait utiliser le programme FACT 1 de décomposition en facteurs premiers et conclure en fonction de l’affichage obtenu.

Cependant, pour répondre à cette question précise, on peut écrire un programme plus rapide.

Problème

Principe

1- Si a =2, ou a = 3, ou a = 5, alors a est premier.

2- Si a est divisible par 2 ou par 3, alors a n’est pas premier.

3- On applique successivement différents diviseurs N à a, en appliquant le principe de la fiche précédente.

Si a est divisible par N, alors a n’est pas premier.

Sinon on reprend à 3 jusqu’à ce que N ≤√ A. Dans ce cas a est premier.

Un nombre a étant donné,

UN NOMBRE EST-IL PREMIER

Utilisation On lance le programme.

Exemple: 147

Exemple: 12347

Exemple: 1524323579

Dans ce cas, il faut être patient.

En effet, la calculatrice met environ 7 minutes

pour afficher le résultat.

(2)

NOMBRES G RIP

CASIO

ClrText ClrTextClrText ClrText ClrTextäääää

"N EST-IL PREMIER?"

"N EST-IL PREMIER?""N EST-IL PREMIER?"

"N EST-IL PREMIER?"

"N EST-IL PREMIER?"äääää

"N="?áA

"N="?áA"N="?áA

"N="?áA

"N="?áAäääää

If A=2 Or A=3 Or A=5 If A=2 Or A=3 Or A=5If A=2 Or A=3 Or A=5 If A=2 Or A=3 Or A=5 If A=2 Or A=3 Or A=5äääää Then "PREMIER":Stop Then "PREMIER":StopThen "PREMIER":Stop Then "PREMIER":Stop Then "PREMIER":Stopäääää IfEnd

IfEndIfEnd IfEnd IfEndäääää

For 2áN To 3 For 2áN To 3For 2áN To 3 For 2áN To 3 For 2áN To 3äääää If Frac (A§N)=0 If Frac (A§N)=0If Frac (A§N)=0 If Frac (A§N)=0 If Frac (A§N)=0äääää

Then "NON PREMIER":Stop Then "NON PREMIER":StopThen "NON PREMIER":Stop Then "NON PREMIER":Stop Then "NON PREMIER":Stopäääää IfEnd

IfEndIfEnd IfEnd IfEndäääää Next NextNext Next Nextäääää

5áN:2áM:ù2áJ 5áN:2áM:ù2áJ5áN:2áM:ù2áJ 5áN:2áM:ù2áJ 5áN:2áM:ù2áJäääää Do

DoDo Do Doäääää

If Frac (A§N)=0 If Frac (A§N)=0If Frac (A§N)=0 If Frac (A§N)=0 If Frac (A§N)=0äääää

Then "NON PREMIER":Stop Then "NON PREMIER":StopThen "NON PREMIER":Stop Then "NON PREMIER":Stop Then "NON PREMIER":Stopäääää Else N+MáN

Else N+MáNElse N+MáN Else N+MáN Else N+MáNäääää ùJáJ

ùJáJùJáJ ùJáJ ùJáJäääää M+JáM M+JáMM+JáM M+JáM M+JáMäääää

LpWhile NÆ•A LpWhile NÆ•ALpWhile NÆ•A LpWhile NÆ•A LpWhile NÆ•Aäääää

"PREMIER"

"PREMIER""PREMIER"

"PREMIER"

"PREMIER"

NB PREM?

Nom du programme

Prog 7

N° du programme

A N N

diviseurs successifs 'NB PREM?ä

'NB PREM?ä 'NB PREM?ä 'NB PREM?ä 'NB PREM?ä

"N EST-IL PREMIER?"ä

"N EST-IL PREMIER?"ä

"N EST-IL PREMIER?"ä

"N EST-IL PREMIER?"ä

"N EST-IL PREMIER?"ä

"N="?ÊAä

"N="?ÊAä

"N="?ÊAä

"N="?ÊAä

"N="?ÊAä A=2…Goto 5ä A=2…Goto 5ä A=2…Goto 5ä A=2…Goto 5ä A=2…Goto 5ä A=3…Goto 5ä A=3…Goto 5ä A=3…Goto 5ä A=3…Goto 5ä A=3…Goto 5ä A=5…Goto 5ä A=5…Goto 5ä A=5…Goto 5ä A=5…Goto 5ä A=5…Goto 5ä 2ÊNä

2ÊNä2ÊNä 2ÊNä 2ÊNä

Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä 3ÊNä

3ÊNä3ÊNä 3ÊNä 3ÊNä

Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä 5ÊN:2ÊM:2ÊJä

5ÊN:2ÊM:2ÊJä 5ÊN:2ÊM:2ÊJä 5ÊN:2ÊM:2ÊJä 5ÊN:2ÊM:2ÊJä Lbl 0ä

Lbl 0ä Lbl 0ä Lbl 0ä Lbl 0ä

Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä Frac (A/N)=0…Goto 9ä N+MÊNä

N+MÊNä N+MÊNä N+MÊNä N+MÊNä -JÊJä -JÊJä -JÊJä -JÊJä -JÊJä M+JÊMä M+JÊMä M+JÊMä M+JÊMä M+JÊMä N NN N

N≤√A…Goto 0äA…Goto 0äA…Goto 0äA…Goto 0äA…Goto 0ä Lbl 5ä

Lbl 5ä Lbl 5ä Lbl 5ä Lbl 5ä

"PREMIER":Goto 2ä

"PREMIER":Goto 2ä

"PREMIER":Goto 2ä

"PREMIER":Goto 2ä

"PREMIER":Goto 2ä Lbl 9ä

Lbl 9ä Lbl 9ä Lbl 9ä Lbl 9ä

"NON PREMIER"ä

"NON PREMIER"ä

"NON PREMIER"ä

"NON PREMIER"ä

"NON PREMIER"ä Lbl 2

Lbl 2 Lbl 2 Lbl 2 Lbl 2

diviseurs successifs

Indications Dans le programme de droite, on utilise l’instruction Stop, qui termine l’exécution d’un programme.

En particulier cette instruction placée dans une boucle (For … Next ; Do … LpWhile ; While … WhileEnd) permet d’arrêter l’exécution du programme, sans qu’un message d’erreur ne soit affiché.

La GRAPH 20 ne dispose pas des opérateurs logiques. Pour éviter des modifications du programme de droite, on peut utiliser le programme de gauche, tel quel.

UN NOMBRE

EST-IL PREMIER ?

Références

Documents relatifs

Décompose en produit de facteurs premiers le nombre

Décompose en produit de facteurs premiers le nombre

Décompose en produit de facteurs premiers le nombre

Décompose en produit de facteurs premiers le nombre

Lors- que le calcul logarithmique ne donne pas un nombre suffisant de chiffres sur lesquels on peut compter, on peut obtenir le dernier, les deux ou les trois derniers, en

4 Détermine le premier nombre entier impair qui possède trois facteurs premiers

4  Détermine le premier nombre entier impair qui possède trois facteurs premiers

[r]