Cod sursa(job #43165)

Utilizator taloibogdanTaloi Bogdan Cristian taloibogdan Data 29 martie 2007 21:07:30
Problema Fractii Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.17 kb
Program fractii;
Var f:text;
    n,s,i,j:longint;
function prime_intre_ele(a,b:longint):boolean;
var r:longint;
begin
 repeat
  r:=a mod b;
  a:=b;
  b:=r;
 until(r=0);
 prime_intre_ele:=false;
 if a=1 then prime_intre_ele:=true;
end;
Begin
  assign(f,'fractii.in');
  reset(f);
  readln(f,n);
  close(f);
  s:=2*n-1+2*n-4;
  for i:=2 to n-2 do
     for j:=i+2 to n do
        if not((i mod 2=0) and (j mod 2=0)) then
          if not((i mod 3=0) and (j mod 3=0)) then
            if not((i mod 5=0) and (j mod 5=0)) then
              if not((i mod 7=0) and (j mod 7=0)) then
                if not((i mod 11=0) and (j mod 11=0)) then
                  if not((i mod 13=0) and (j mod 13=0)) then
                    if not((i mod 17=0) and (j mod 17=0)) then
                      if not((i mod 19=0) and (j mod 19=0)) then
        if not((i mod 23=0) and (j mod 23=0)) then
          if not((i mod 29=0) and (j mod 29=0)) then
            if not((i mod 31=0) and (j mod 31=0)) then
              if not((i mod 37=0) and (j mod 37=0)) then
                if not((i mod 41=0) and (j mod 41=0)) then
                  if not((i mod 43=0) and (j mod 43=0)) then
                    if not((i mod 47=0) and (j mod 47=0)) then
                      if not((i mod 53=0) and (j mod 53=0)) then
        if not((i mod 59=0) and (j mod 59=0)) then
          if not((i mod 61=0) and (j mod 61=0)) then
            if not((i mod 67=0) and (j mod 67=0)) then
              if not((i mod 71=0) and (j mod 71=0)) then
                if not((i mod 73=0) and (j mod 73=0)) then
                  if not((i mod 79=0) and (j mod 79=0)) then
                    if not((i mod 83=0) and (j mod 83=0)) then
                      if not((i mod 89=0) and (j mod 89=0)) then
        if not((i mod 97=0) and (j mod 97=0)) then
          if not((i mod 101=0) and (j mod 101=0)) then
            if not((i mod 103=0) and (j mod 103=0)) then
                        if j mod i>0 then
                          if j mod i=1 then s:=s+2
                                       else if prime_intre_ele(i,j) then s:=s+2;
  assign(f,'fractii.out');
  rewrite(f);
  Writeln(f,s);
  close(f);
End.