Cod sursa(job #280236)

Utilizator anthraxztAndrei Tatar anthraxzt Data 13 martie 2009 11:55:40
Problema Pascal Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.65 kb
program numere;
uses math;
var r,i,j,d,s1,s2,s3,l1,l2,l3,c:longword;
    y:boolean;
    f:text;
begin
 assign(f,'pascal.in');reset(f);
 readln(f,r,d);
 close(f);
 c:=0;
 for i:=1 to (r+1)div 2 do
  begin
   s1:=0;s2:=0;s3:=0;
   l1:=trunc(logn(d,r));
   l2:=trunc(logn(d,i));
   l3:=trunc(logn(d,r-i));
   for j:=1 to l1 do inc(s1,trunc(intpower(d,j)));
   for j:=1 to l2 do inc(s2,trunc(intpower(d,j)));
   for j:=1 to l3 do inc(s3,trunc(intpower(d,j)));
   if s1-s2-s3>0 then begin if i=(r+1)div 2 then y:=true; inc(c); end;
  end;
 assign(f,'pascal.out');rewrite(f);
 if (r and 1=0)and y then write(f,2*c-1) else write(f,2*c);
 close(f);
end.