Cod sursa(job #609006)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 18 august 2011 23:43:04
Problema Suma divizorilor Scor 40
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.32 kb
Program suma_divizorilor;
const md=9901;
 var a,b,i,j,d,s,x:longint;
     p:array [1..10000] of boolean;
     c:array [1..2000] of longint;
     fi,fo:text;
function pow(a,b:int64):int64;
begin
pow:=1;
 while b>0 do
   if b mod 2=0 then begin
                      a:=a*a;
                      a:=a mod md;
                      b:=b div 2;
                      end
    else begin
          pow:=pow*a;
          pow:=pow mod md;
          dec(b);
          end;
end;
begin
assign(fi,'sumdiv.in');
 assign(fo,'sumdiv.out');
reset(fi);
 rewrite(fo);
readln(fi,a,b);
  for i:=2 to 10000 do
                if not p[i] then begin
                  for j:=2 to 10000 div i do
                                     p[i*j]:=true;
                  inc(x);
                  c[x]:=i;
                  end;
 i:=1; s:=1;
 while (i<x) and (a>1) and (c[i]<=trunc(sqrt(a))) do
  if a mod c[i]<>0 then inc(i)
   else begin
         d:=0;
          repeat
           inc(d);
           a:=a div c[i];
           until (a=1) or (a mod c[i]<>0);
          d:=d*b;
         s:=s*(pow(c[i],d+1)-1); s:=s mod md;
          s:=s*(pow(c[i]-1,md-2)); s:=s mod md;
           end;
 if a>1 then begin
                s:=s*((a+1) mod md);
                 s:=s mod md;
               end;
 write(fo,s);
close(fo);
end.