Advertisement
ArfIsAToe

kahla

May 26th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.14 KB | None | 0 0
  1. program kahla;
  2. uses WinCrt;
  3. type
  4.     tab = array[1..100] of integer ;
  5. var
  6.     a,b : integer;
  7. { Prem t3abilek tableau bel a3ded el premier elli tnajem testa3mlhom lkol
  8.     a=150 < b = 170
  9.     lim := 170
  10.     T : 2  3  5  7  13  17  19  23  29  37  47  59  67  79  
  11. }
  12. function prem(x : integer ):Boolean;
  13.     var
  14.         a: integer;
  15.     begin
  16.         a:=2;
  17.         while (x mod a <> 0 ) and (a<= x div 2 ) do
  18.             a:=a+1;
  19.     end;   
  20.     procedure rempt(var t : tab ; var n : integer ; a,b : integer );
  21.         var
  22.             lim,x : integer;
  23.         Begin
  24.             if a>b then
  25.                 lim:=a
  26.             Else
  27.                 lim:=b;
  28.             n:=0;
  29.             for x:=2 to lim div 2 do
  30.                     if prem(x) then
  31.                         begin
  32.                             n:=n+1;
  33.                             t[n]:=x;  
  34.                         end;
  35.         end;
  36.         { procedure decomp t3abilek el tableau elli ta3tihoulha bel puissance mta3 kol 3dad premier testa3mlo
  37.          Exple : a = 150 = 2 * 3 * 5^2
  38.          Ta : 1  1  2  0  0  0  0  ....
  39.                          b = 170 = 2 * 5 * 17
  40.          Tb : 1  0  1  0  0  1  0  0  0  ....
  41.          }
  42.         Procedure decomp(var ty : tab ;t : tab ; y,n: integer);
  43.             var
  44.                 p,a: integer ;
  45.             Begin
  46.                 for a:=1 to n do
  47.                     Begin
  48.                         p:=0;
  49.                         while y mod t[a] = 0 do
  50.                             begin
  51.                                 p:=p+1;
  52.                                 y:=y div t[a];
  53.                             end;
  54.                         ty[a]:=p;
  55.                     end;   
  56.             End;
  57.             Procedure aff(a,b : integer );
  58.                 var
  59.                     t,ta,tb : tab ;
  60.                     n,i : integer ;
  61.                 Begin
  62.                     rempt(t,n,a,b);
  63.                     decomp(ta,t,a,n);
  64.                     decomp(tb,t,b,n);
  65.                     write(a:6,'= ');
  66.                     for i:=1 to n do
  67.                         Begin
  68.                             if ta[i] <> 0 then
  69.                                 if i<n then
  70.                                     write(t[i],'^',ta[i],' * ')
  71.                                 Else
  72.                                     write(t[i],'^',ta[i]);
  73.                         end;
  74.                     writeln;
  75.                     write(b:6,'= ');
  76.                     for i:=1 to n do
  77.                         Begin
  78.                             if tb[i] <> 0 then
  79.                                 if i<n then
  80.                                     write(t[i],'^',tb[i],' * ')
  81.                                 Else
  82.                                     write(t[i],'^',tb[i]);
  83.                         end;
  84.                         writeln;
  85.                         write('PGCD(',a,';',b,') = ');
  86.                         for i :=1 to n do
  87.                             begin
  88.                                 if (0<tb[i]) and (ta[i] > 0 ) then
  89.                                     if ta[i] < tb[i] then
  90.                                         write(t[i],'^',ta[i],' * ')
  91.                                     Else
  92.                                         write(t[i],'^',tb[i],' * ');
  93.                             end ;                      
  94.                 end;
  95. begin
  96.     write('A= ');
  97.      readln(a);
  98.     write('B= ');
  99.      Readln(b);
  100.     aff(a,b);
  101. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement