Pascal

Modified: Wednesday, 22-12-2021 07:00 AM

Nguyên tố tương đương là 2 số có cùng các ước nguyên tố


var a,b:longint;
    i,ja,jb:integer;
    mA,mB:array[1..100]of integer;
    Bo:boolean;
begin
     write('Nhap so A: '); readln(a);
     write('Nhap so B: '); readln(b);
     i:=2;ja:=0;
     while a>1 do
     begin
           if a mod i=0 then
           begin
              inc(ja);
              mA[ja]:=i;
              while a mod i=0 do
              a:=a div i;
           end;
           inc(i);
     end;
     i:=2;jb:=0;
     while b>1 do
     begin
           if b mod i=0 then
           begin
              inc(jb);
              mB[jb]:=i;
              while b mod i=0 do
              b:=b div i;
           end;
           inc(i);
     end;
     Bo:=true;
     if ja<>jb then Bo:=false
     else
        for i:=1 to ja do
        if mA[i]<>mB[i] then
        begin
           Bo:=false;
           break;
        end;
     if Bo then write('Nguyen to tuong duong')
     else write('Khong phai nguyen to tuong duong');  
     readln;
end.