Cod sursa(job #451003)

Utilizator gramatovici_paulGramatovici Paul gramatovici_paul Data 8 mai 2010 20:20:26
Problema Mins Scor 15
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.95 kb
var max,min,c,s,d,i,j:longint;
function prime(a,b:longint):boolean;
var k,i:longint;
begin
  k:=trunc(sqrt(a));
  prime:=true;
  for i:=2 to k do
      if a mod i=0 then
         begin
           if b mod i=0 then
              begin
                prime:=false;
                break;
              end;
           a:=a div i;
           while a mod i=0 do
               a:=a div i;
         end;
  if (a<>1) and (b mod a=0) then prime:=false;
end;
begin
  assign(input,'mins.in');
  assign(output,'mins.out');
  reset(input);
  rewrite(output);
  readln(c,d);
  if c<d then
     begin
       min:=c-1;
       max:=d-1;
     end
  else
     begin
       min:=d-1;
       max:=c-1;
     end;
  s:=0;
  for i:=2 to min do
     for j:=1 to i-1 do
        if prime(i,j)=true then inc(s);
  s:=s*2;
  for i:=min+1 to max do
     for j:=1 to min do
        if prime(i,j)=true then inc(s);
  writeln(s+1);
  close(output);
end.