Advertisement
LOVEGUN

Bac 2016

May 9th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.32 KB | None | 0 0
  1. Program bac2016;
  2. Uses Wincrt;
  3. Var
  4.   n: Integer;
  5. Procedure saisie (Var n:Integer);
  6. Begin
  7.   Repeat
  8.     Write ('Saisir N: ');
  9.     Readln (n);
  10.   Until (2<=n) And (n<=5);
  11. End;
  12. Function fact (n:Integer): Longint;
  13. Var
  14.   i,r: Longint;
  15. Begin
  16.   r := 1;
  17.   For i:=1 To n Do
  18.         begin
  19.             r := r*i;
  20.         end;
  21.   fact := r;
  22. End;
  23. function premier (n:integer):Boolean;
  24. Var
  25.     r,i:integer;
  26. Begin
  27. r:=0;
  28. for i:=2 to n Do
  29.     if (n mod i =0) Then
  30.         r:=r+1;
  31. premier:=r=1;
  32. end;
  33. Function factp (n:Integer): Longint;
  34. Var
  35.   i,r: Longint;
  36. Begin
  37.   r := 1;
  38.   For i:=1 To n Do
  39.         begin
  40.             if premier(i) Then
  41.             r := r*i;
  42.         end;
  43.   factp := r;
  44. End;
  45. Procedure traitement (n:Integer);
  46. Var
  47.   r,nf,np: Longint;
  48. Begin
  49.   nf := 0;
  50.     np:=0;
  51.   r := 0;
  52.   Repeat
  53.     r := r+1;
  54.     If (premier(fact(r)+1)) and (nf<n) then
  55.       Begin
  56.         nf := nf+1;
  57.                 writeln ('PF : ',fact(r)+1);
  58.       End;
  59.         If  (premier(fact(r)-1)) and (nf<n) Then
  60.       Begin
  61.         nf := nf+1;
  62.                 writeln ('PF : ',fact(r)-1);
  63.       End;
  64.         If (premier(factp(r)+1)) and (np<n) then
  65.       Begin
  66.         np := np+1;
  67.                 writeln ('PP : ',factp(r)+1);
  68.       End;
  69.         If  (premier(factp(r)-1)) and (np<n) Then
  70.       Begin
  71.         np := np+1;
  72.                 writeln ('PP : ',factp(r)-1);
  73.       End;
  74.   Until (nf=n) and (np=n);
  75. End;
  76. Begin
  77.   saisie (n);
  78.   traitement (n);
  79. End.
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement