Cod sursa(job #756813)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 10 iunie 2012 14:56:03
Problema Suma divizorilor Scor 0
Compilator fpc Status done
Runda Remember Mihai Pătrașcu Marime 2.04 kb
Program sumdiv2;
 var p:array [1..1000] of boolean;
     a:array [1..100000,1..2] of longint;
     b:array [1..200] of integer;
     sol:array [0..1000000] of int64;
     b1,b2:array [1..1 shl 15] of char;
     i,j,n,k,min,max,d,t,x:longint;
     s:int64;
     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;
                      b:=b div 2;
                      end
    else begin
          pow:=pow*a;
          dec(b);
          end;
end;
begin
 assign(fi,'sumdiv2.in');
  assign(fo,'sumdiv2.out');
 settextbuf(fi,b1);
  settextbuf(fo,b2);
 reset(fi);
  rewrite(fo);
 readln(fi,n);
 for i:=2 to 1000 do
  if p[i]=false then begin
                 for j:=2 to 1000 div i do p[i*j]:=true;
                 inc(k); b[k]:=i;
                 end;
  min:=1000000;
 for i:=1 to n do begin
                  readln(fi,a[i,1],a[i,2]);
                  if a[i,1]<min then min:=a[i,1];
                  if a[i,2]>max then max:=a[i,2];
                  end;
 for i:=min to max do begin
                        j:=1;  x:=i;  s:=1;  d:=0;
                         repeat
                         if x mod b[j]<>0 then inc(j)
                          else begin
                             d:=0;
                              repeat
                                 x:=x div b[j];
                                 inc(d);
                                 until (x mod b[j]<>0) or (x=1) or (j>k);
                            s:=s*(pow(b[j],d+1)-1);
                            s:=trunc((s)/(b[j]-1));
                            inc(j);
                            end;
                          until (x=1) or (j>k);
   if x>1 then s:=s*(n+1);
  { inc(t);}
   {sol[t]:=sol[t-1]+s;}
    sol[i]:=s;
 end;
 s:=0;
 for i:=1 to n do begin
 { if a[i,1]>min then writeln(fo,trunc(sol[a[i,2]-min+1]-sol[a[i,1]-min]))
   else writeln(fo,trunc(sol[a[i,2]-min+1]));  }
 for j:=a[i,1] to a[i,2] do s:=s+sol[j];
 writeln(fo,s);
 s:=0;
 end;
close(fo);
end.