LOVEGUN

Bac 2011 26/05 (rework)

Jan 9th, 2021 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.34 KB | None | 0 0
  1. Program bac2011;
  2. Uses Wincrt;
  3. Var
  4.   f: Text;
  5.   a,b: Longint;
  6.  
  7. Function premier (x:Longint): Boolean;
  8. Var
  9.   i,nb: Longint;
  10. Begin
  11.   nb := 0;
  12.   premier := False;
  13.   For i:=x Downto 2 Do
  14.     If (x Mod i) = 0 Then
  15.       nb := nb+1;
  16.   If nb=1 Then
  17.     premier := True;
  18. End;
  19. Function puis (entier,facteur:Longint): Longint;
  20. Var
  21.   j,i: Longint;
  22. Begin
  23.   j := 1;
  24.   For i:=1 To facteur Do
  25.     j := j*2;
  26.   puis := j;
  27. End;
  28.  
  29. Procedure creation (Var f:Text);
  30. Begin
  31.   Assign (f,'c:/bac/mersenne.txt');
  32. End;
  33. Procedure saisie (Var a,b:Longint);
  34. Begin
  35.   Repeat
  36.     Write ('Saisir A: ');
  37.     Readln (a);
  38.     Write ('Saisir B: ');
  39.     Readln (b);
  40.   Until (2<a) And (a<b) And (b<50000);
  41. End;
  42. Procedure traitement (Var f:Text;a,b:Longint);
  43. Var
  44.   aux,x,i: Longint;
  45. Begin
  46.   Rewrite (f);
  47.   For i:=a To b Do
  48.     Begin
  49.       aux := 0;
  50.       Repeat
  51.         aux := aux+1;
  52.         x := puis(2,aux)-1;
  53.       Until (x>=i);
  54.       If (x=i) And (premier(i)) Then
  55.         Writeln (f,x,'=(2^',aux,')-1');
  56.     End;
  57.   Close (f);
  58. End;
  59. Procedure affiche (Var f:Text);
  60. Var
  61.   ch: String;
  62. Begin
  63.   Reset (f);
  64.   If Eof(f) Then Writeln ('Le fichier est vide');
  65.   While Not (Eof(f)) Do
  66.     Begin
  67.       Readln (f,ch);
  68.       Writeln (ch);
  69.     End;
  70.   Close (f);
  71. End;
  72. Begin
  73.   creation (f);
  74.   saisie (a,b);
  75.   traitement (f,a,b);
  76.   affiche (f);
  77. End.
  78.  
Add Comment
Please, Sign In to add comment