Forum INFOMATH
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Le Deal du moment :
ETB Pokémon Fable Nébuleuse : où ...
Voir le deal

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

3 participants

Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par nejah Ven 27 Mai - 2:28

program nombre_mersenne;
uses wincrt;
var
a,b,nb:longint;
mersenne:text;

Code:
procedure creation(var mersenne:text);
begin
assign(mersenne,'mersenne.txt');
rewrite(mersenne);
end;

Code:
procedure saisir(var a,b:longint);
begin
repeat
write('A=');
readln(a);
until (a>2) and( a<49999);
repeat
write('B=');
readln(b);
until (b>a) and (b<50000);
end;

Code:
function puissance(x,y:longint):longint;
begin
if y=0 then
puissance:=1
else
puissance:=x*puissance(x,y-1);
end;

Code:
function premier(n:longint):boolean;
var
i:longint;
begin
i:=2;
while (n mod i <>0) and (i<=n div 2) do
i:=i+1;
premier:=i>n div 2;
end;

Code:
procedure determine_mersenne(var nb:longint;a,b:longint;var mersenne:text);
var
m,n:longint;
begin
append(mersenne);
nb:=0;
for m:=a to b do
begin
n:=2;
while puissance(2,n)-1<m do
n:=n+1;
if (m=puissance(2,n)-1) and (premier(n)) then
begin
writeln(mersenne,m,'=(2^',n,')-1');
nb:=nb+1;
end;
end;
end;

Code:
procedure afficher(var mersenne:text;nb:longint);
var
ch:string;
begin
reset(mersenne);
if nb=0 then
writeln('Il n''y''à nombre de mersenne')
else
while not (eof(mersenne)) do
begin
readln(mersenne,ch);
writeln(ch);
end;
end;

Code:
begin
saisir(a,b);
creation(mersenne);
determine_mersenne(nb,a,b,mersenne);
afficher(mersenne,nb);
close(mersenne);
end.

nejah
Entier Naturel
Entier Naturel

Masculin
Nombre de messages : 21
Localisation : Tunisie
Réputation : 3
Points : 4967
Date d'inscription : 14/11/2010

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue1000/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (1000/1000)

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par Napoléon Ven 27 Mai - 10:01


Merci pour le partage de la solution !!
Napoléon
Napoléon
Admin
Admin

Masculin
Nombre de messages : 2934
Localisation : Tunisie
Réputation : 122
Points : 7684
Date d'inscription : 19/03/2007

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue999/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (999/1000)

https://infomath.1fr1.net

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par Napoléon Ven 27 Mai - 10:05


while (n mod i <>0) and (i<=n div 2) do

Pour vérifier si "n" est premier ou non, il suffit d'aller jusqu'à "SQRT(n)" et non pas à "n DIV 2".
Napoléon
Napoléon
Admin
Admin

Masculin
Nombre de messages : 2934
Localisation : Tunisie
Réputation : 122
Points : 7684
Date d'inscription : 19/03/2007

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue999/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (999/1000)

https://infomath.1fr1.net

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par nejah Sam 28 Mai - 0:09

nabiL a écrit:
while (n mod i <>0) and (i<=n div 2) do

Pour vérifier si "n" est premier ou non, il suffit d'aller jusqu'à "SQRT(n)" et non pas à "n DIV 2".

Merci pour cet information qui optimise ma solution et diminue le temps d'exécution de ce programme

nejah
Entier Naturel
Entier Naturel

Masculin
Nombre de messages : 21
Localisation : Tunisie
Réputation : 3
Points : 4967
Date d'inscription : 14/11/2010

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue1000/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (1000/1000)

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par Napoléon Sam 28 Mai - 16:05

nejah a écrit:
nabiL a écrit:
while (n mod i <>0) and (i<=n div 2) do

Pour vérifier si "n" est premier ou non, il suffit d'aller jusqu'à "SQRT(n)" et non pas à "n DIV 2".

Merci pour cet information qui optimise ma solution et diminue le temps d'exécution de ce programme

De rien. Bienvenue au forum. Par la même occasion, si tu es passionné de programmation, je t'invite à me contacter sur Skype: nabil.belgasmi.
Je peux t'être utile.
Napoléon
Napoléon
Admin
Admin

Masculin
Nombre de messages : 2934
Localisation : Tunisie
Réputation : 122
Points : 7684
Date d'inscription : 19/03/2007

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue999/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (999/1000)

https://infomath.1fr1.net

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par nejah Sam 28 Mai - 23:16

nabiL a écrit:
nejah a écrit:
nabiL a écrit:
while (n mod i <>0) and (i<=n div 2) do

Pour vérifier si "n" est premier ou non, il suffit d'aller jusqu'à "SQRT(n)" et non pas à "n DIV 2".

Merci pour cet information qui optimise ma solution et diminue le temps d'exécution de ce programme

De rien. Bienvenue au forum. Par la même occasion, si tu es passionné de programmation, je t'invite à me contacter sur Skype: nabil.belgasmi.
Je peux t'être utile.

Je vous ai ajouter sur Skype Admin

nejah
Entier Naturel
Entier Naturel

Masculin
Nombre de messages : 21
Localisation : Tunisie
Réputation : 3
Points : 4967
Date d'inscription : 14/11/2010

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue1000/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (1000/1000)

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par methodiX Lun 30 Mai - 10:38


Solution élégante! Chokran.
methodiX
methodiX
Admin
Admin

Masculin
Nombre de messages : 1260
Localisation : Le couloir de l'école polytechnique de Tunis
Réputation : 68
Points : 7066
Date d'inscription : 22/03/2007

Feuille de personnage
Capacité linguistique:
Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Left_bar_bleue1000/1000Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty_bar_bleue  (1000/1000)

Revenir en haut Aller en bas

Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute) Empty Re: Corrigé bac pratique 2011 Sciences Informatique (8h 30 minute)

Message par Contenu sponsorisé


Contenu sponsorisé


Revenir en haut Aller en bas

Revenir en haut

- Sujets similaires

 
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum