Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program bac2011;
- Uses Wincrt;
- Var
- f: Text;
- a,b: Longint;
- Function premier (x:Longint): Boolean;
- Var
- i,nb: Longint;
- Begin
- nb := 0;
- premier := False;
- For i:=x Downto 2 Do
- If (x Mod i) = 0 Then
- nb := nb+1;
- If nb=1 Then
- premier := True;
- End;
- Function puis (entier,facteur:Longint): Longint;
- Var
- j,i: Longint;
- Begin
- j := 1;
- For i:=1 To facteur Do
- j := j*2;
- puis := j;
- End;
- Procedure creation (Var f:Text);
- Begin
- Assign (f,'c:/bac/mersenne.txt');
- End;
- Procedure saisie (Var a,b:Longint);
- Begin
- Repeat
- Write ('Saisir A: ');
- Readln (a);
- Write ('Saisir B: ');
- Readln (b);
- Until (2<a) And (a<b) And (b<50000);
- End;
- Procedure traitement (Var f:Text;a,b:Longint);
- Var
- aux,x,i: Longint;
- Begin
- Rewrite (f);
- For i:=a To b Do
- Begin
- aux := 0;
- Repeat
- aux := aux+1;
- x := puis(2,aux)-1;
- Until (x>=i);
- If (x=i) And (premier(i)) Then
- Writeln (f,x,'=(2^',aux,')-1');
- End;
- Close (f);
- End;
- Procedure affiche (Var f:Text);
- Var
- ch: String;
- Begin
- Reset (f);
- If Eof(f) Then Writeln ('Le fichier est vide');
- While Not (Eof(f)) Do
- Begin
- Readln (f,ch);
- Writeln (ch);
- End;
- Close (f);
- End;
- Begin
- creation (f);
- saisie (a,b);
- traitement (f,a,b);
- affiche (f);
- End.
Add Comment
Please, Sign In to add comment