Advertisement
LOVEGUN

Bac 2019 #2

Apr 2nd, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.85 KB | None | 0 0
  1. Program bac2019meth2;
  2. Uses Wincrt;
  3. Type
  4.   pp = Record
  5.     a,b,ppcm: Integer;
  6.   End;
  7.   tab = Array [1..100] Of pp;
  8.   tfact = Array [1..1000] Of Integer;
  9. Var
  10.   t: tab;
  11.   n: Integer;
  12.  
  13. Procedure saisie (Var n:Integer);
  14. Begin
  15.   Repeat
  16.     Writeln ('Saisir N: ');
  17.     Readln (n);
  18.   Until (1<=n) And (n<=100);
  19. End;
  20.  
  21. Procedure init (Var t:tfact);
  22. Var
  23.   i: Integer;
  24. Begin
  25.   For i:=1 To 1000 Do
  26.     t[i] := 0;
  27. End;
  28.  
  29. Procedure fact (Var ta:tfact;a:Integer;var c:integer);
  30. Var
  31.   i,d: Integer;
  32. Begin
  33.   d := 2;
  34.     c:=0;
  35.   Repeat
  36.     If a Mod d =0 Then
  37.       Begin
  38.         ta[d] := ta[d]+1;
  39.                 if c<d Then
  40.                     c:=d;
  41.                 a := a Div d;
  42.         d := 2;
  43.       End
  44.     Else
  45.       d := d+1;
  46.   Until (a Div d=0);
  47. End;
  48. Function puis (entier,facteur:Longint): Longint;
  49. Var
  50.   j,i: Longint;
  51. Begin
  52.   j := 1;
  53.   For i:=1 To facteur Do
  54.     j := j*entier;
  55.   puis := j;
  56. End;
  57. Procedure traitement (Var t:tab;n:Integer);
  58. Var
  59.   ta,tb: tfact;
  60.     i,j,somme,k1,k2: Integer;
  61. Begin
  62.   For j:=1 To n Do
  63.         With t[j] Do
  64.       Begin
  65.         Repeat
  66.           Write ('Saisir a: ');
  67.           Readln (a);
  68.         Until (a<1000) And (0<a);
  69.         Repeat
  70.           Write ('Saisir b: ');
  71.           Readln (b);
  72.         Until (b<1000) And (0<b);
  73.         init (ta); fact (ta,a,k1);
  74.         init (tb); fact (tb,b,k2);
  75.         somme := 1;
  76.         For i:=1 To k1 Do
  77.           If (ta[i]<tb[i]) And (ta[i]<>0) Then
  78.               somme := somme*puis(i,tb[i])
  79.           Else
  80.               somme := somme*puis(i,ta[i]);
  81.         For i:=1 To k2 Do
  82.           If (tb[i]<>0) And (ta[i]=0) Then
  83.               somme := somme*puis(i,tb[i]);
  84.                 ppcm:=somme;
  85.       End;
  86. End;
  87. procedure affiche (t:tab;n:integer);
  88. Var
  89. i:integer;
  90. Begin
  91.     for i:=1 to n Do
  92.         writeln ('PPCM(',t[i].a,',',t[i].b,'): ',t[i].ppcm);
  93. end;
  94. Begin
  95.   saisie (n);
  96.   traitement (t,n);
  97.     affiche (t,n);
  98. End.
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement