Cod sursa(job #251823)

Utilizator FllorynMitu Florin Danut Flloryn Data 3 februarie 2009 13:58:13
Problema Suma divizorilor Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.3 kb
    var p,v:array[0..100] of longint;   f,g:text;      rez,a,b,i:longint;  
     
    function pow(n,k:longint):longint;  
    var x:longint;  
    begin  
       if k=1 then  pow:=n  
             else begin  
                  x:=pow(n,k shr 1);  
                  if k and 1=0 then pow:=(x*x) mod 9901  
                               else pow:=(((x*x) mod 9901)*n) mod 9901;  
                  end;  
   end;  
     
   function s(a,b:longint):longint;  
   begin  
       if b=1 then s:=a  else  
       if b=0 then s:=0  else begin  
                              if b and 1=0 then  s:=s(a,b shr 1)*(1+pow(a,b shr 1)) mod 9901 
                                           else  s:=(a*(1+s(a,b-1))) mod 9901;  
                              end;  
   end;  
    
   begin  
    assign(f,'sumdiv.in'); reset(f);  
    assign(g,'sumdiv.out'); rewrite(g);  
    read(f,a,b);  
    p[0]:=0;  
    if a and 1=0 then begin  
                      p[0]:=1;  
                      p[1]:=2;  
                      while a and 1=0 do begin  
                                         inc(v[1]);  
                                         a:=a shr 1;  
                                         end;  
                      end;  
   i:=3;  
   while (i<=trunc(sqrt(a))) do begin  
                                if a mod i=0 then begin  
                                                 inc(p[0]);  
                                                 p[p[0]]:=i;  
                                                 while a mod i=0 do begin  
                                                                    inc(v[p[0]]);  
                                                                    a:=a div i;  
                                                                    end;  
                                                  end;  
                               inc(i,2);  
                               end;  
    if a<>1 then begin  
                 inc(p[0]);  
                 p[p[0]]:=a;  
                 v[p[0]]:=1;  
                 end;  
   rez:=1;  
   for i:=1 to p[0] do begin  
                       p[i]:=p[i] mod 9901;  
                       rez:=(rez*(s(p[i],v[i]*b)+1)) mod 9901;  
                       end;  
  writeln(g,rez);  
  close(f); close(g);  
  end.