Var n, m, k, i: integer; f:boolean; Function s(a:integer):boolean; Var i:integer; Begin s:=false; For i:=2 to a div 2 do if a mod i=0 then s:=true; End; Begin Write('n = '); Readln(n); Write('m = '); Readln(m); If m<n then k:=m else k:=n; i:=1; f:=s(i); while (i<k) and not f do begin i:=i+1; if (m mod i=0)and(n mod i=0) then f:=s(i); end; if f then writeln('НОД = ', i) else writeln('Нет требуемого делителя'); End.
Program pr1; Var m, n, i, j:integer; Function isitsimple (x:integer) :boolean; Var i:integer; Begin isitsimple:=false; For i:=2 to x-1 do if x mod i=0 then isitsimple:=true; End; Begin Writeln('input m') ; Readln(m) ; Writeln('input n') ; Readln(n) ; If m>n then j:=m; For i:=1 to j do if (m mod i=0) and(n mod i=0) then If isitsimple(i) then Begin writeln('NOD: ', i) ; Break; End; End.
Function s(a:integer):boolean;
Var i:integer;
Begin
s:=false;
For i:=2 to a div 2 do
if a mod i=0 then s:=true;
End;
Begin
Write('n = ');
Readln(n);
Write('m = ');
Readln(m);
If m<n then k:=m else k:=n;
i:=1; f:=s(i);
while (i<k) and not f do
begin
i:=i+1;
if (m mod i=0)and(n mod i=0) then f:=s(i);
end;
if f then writeln('НОД = ', i) else writeln('Нет требуемого делителя');
End.
Пример:
n = 42
m = 105
НОД = 21
Var m, n, i, j:integer;
Function isitsimple (x:integer) :boolean;
Var i:integer;
Begin
isitsimple:=false;
For i:=2 to x-1 do
if x mod i=0 then isitsimple:=true;
End;
Begin
Writeln('input m') ;
Readln(m) ;
Writeln('input n') ;
Readln(n) ;
If m>n then j:=m;
For i:=1 to j do
if (m mod i=0) and(n mod i=0) then
If isitsimple(i) then
Begin
writeln('NOD: ', i) ;
Break;
End;
End.