Cod sursa(job #125904)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 20 ianuarie 2008 20:58:08
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.01 kb
program fractii;
var b,x,y,S,t1,t2 : 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 mod b=0) and (b<>1) then ok := false;
if (b mod a=0) and (a<>1) then ok := false;

if ok then
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;
if ok then                                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.