LOVEGUN

Bac 2011 26/05/2011 #1

Jan 8th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.35 KB | None | 0 0
  1. Program bac2011;
  2. Uses Wincrt;
  3. Var
  4. f:text;
  5. a,b:longint;
  6. Function premier (x:longint): Boolean;
  7. Var
  8.   i,nb: longint;
  9. Begin
  10.   nb := 0;
  11.   premier := False;
  12.   For i:=x Downto 2 Do
  13.     If (x Mod i) = 0 Then
  14.       nb := nb+1;
  15.   If nb=1 Then                              
  16.     premier := True;
  17. End;
  18.  
  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.  
  34. Procedure saisie (Var a,b:Longint);
  35. Begin
  36.   Repeat
  37.     Write ('Saisir A: ');
  38.     Readln (a);
  39.     Write ('Saisir B: ');
  40.     Readln (b);
  41.   Until (2<a) And (a<b) And (b<50000);
  42. End;
  43.  
  44. Procedure traitement (Var f:Text;a,b:Longint);
  45. Var
  46. aux,x,i:longint;
  47. Begin
  48.     rewrite (f);
  49.     for i:=a to b Do
  50.         Begin
  51.             aux:=0;
  52.             Repeat
  53.                 aux := aux+1;
  54.             x := puis(2,aux)-1;
  55.             Until   (x=i) or (aux=14);
  56.             if (premier(x)) and (premier(i)) Then
  57.                 writeln (f,x,'=(2^',aux,')-1');
  58.         end;
  59.     close (f);
  60. End;
  61.  
  62. Procedure affiche (Var f:Text);
  63. Var
  64.   ch: String;
  65. Begin
  66.   Reset (f);
  67.   If Eof(f) Then Writeln ('Le fichier est vide');
  68.   While Not (Eof(f)) Do
  69.     Begin
  70.       Readln (f,ch);
  71.       Writeln (ch);
  72.     End;
  73.   Close (f);
  74. End;
  75. Begin
  76.     creation (f);
  77.     saisie (a,b);
  78.     traitement (f,a,b);
  79.     affiche (f);
  80. End.
  81.  
Add Comment
Please, Sign In to add comment