Cod sursa(job #124681)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 19 ianuarie 2008 18:54:19
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.89 kb
program fractii;
var b,x,y,S : longint;
    f : text;

function prime(a,b:longint):boolean;
var ok : boolean;
    i,j : longint;
begin
ok := true;

if a=b then ok := false;

if a>b then
for i := 2 to b do
if (a mod i=0) and (b mod i = 0) then
                                begin
                                ok := false;
                                break;
                                end;
if a<b then
for j := 2 to a do
if (a mod j=0) and (b mod j = 0) then
                                begin
                                ok := false;
                                break;
                                end;

prime := ok;

end;


begin

assign(f,'fractii.in');
reset(f);
read(f,b);
close(f);


S := 1;

for x := 1 to b do
for y := 1 to b do
if prime(x,y) then S := S+1;

assign(f,'fractii.out');
rewrite(f);
write(f,S);
close(f);

end.