Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program bac2019meth2;
- Uses Wincrt;
- Type
- pp = Record
- a,b,ppcm: Integer;
- End;
- tab = Array [1..100] Of pp;
- tfact = Array [1..1000] Of Integer;
- Var
- t: tab;
- n: Integer;
- Procedure saisie (Var n:Integer);
- Begin
- Repeat
- Writeln ('Saisir N: ');
- Readln (n);
- Until (1<=n) And (n<=100);
- End;
- Procedure init (Var t:tfact);
- Var
- i: Integer;
- Begin
- For i:=1 To 1000 Do
- t[i] := 0;
- End;
- Procedure fact (Var ta:tfact;a:Integer;var c:integer);
- Var
- i,d: Integer;
- Begin
- d := 2;
- c:=0;
- Repeat
- If a Mod d =0 Then
- Begin
- ta[d] := ta[d]+1;
- if c<d Then
- c:=d;
- a := a Div d;
- d := 2;
- End
- Else
- d := d+1;
- Until (a Div d=0);
- End;
- Function puis (entier,facteur:Longint): Longint;
- Var
- j,i: Longint;
- Begin
- j := 1;
- For i:=1 To facteur Do
- j := j*entier;
- puis := j;
- End;
- Procedure traitement (Var t:tab;n:Integer);
- Var
- ta,tb: tfact;
- i,j,somme,k1,k2: Integer;
- Begin
- For j:=1 To n Do
- With t[j] Do
- Begin
- Repeat
- Write ('Saisir a: ');
- Readln (a);
- Until (a<1000) And (0<a);
- Repeat
- Write ('Saisir b: ');
- Readln (b);
- Until (b<1000) And (0<b);
- init (ta); fact (ta,a,k1);
- init (tb); fact (tb,b,k2);
- somme := 1;
- For i:=1 To k1 Do
- If (ta[i]<tb[i]) And (ta[i]<>0) Then
- somme := somme*puis(i,tb[i])
- Else
- somme := somme*puis(i,ta[i]);
- For i:=1 To k2 Do
- If (tb[i]<>0) And (ta[i]=0) Then
- somme := somme*puis(i,tb[i]);
- ppcm:=somme;
- End;
- End;
- procedure affiche (t:tab;n:integer);
- Var
- i:integer;
- Begin
- for i:=1 to n Do
- writeln ('PPCM(',t[i].a,',',t[i].b,'): ',t[i].ppcm);
- end;
- Begin
- saisie (n);
- traitement (t,n);
- affiche (t,n);
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement