智商太低了

详细题解在这里http://blog.csdn.net/zmoiynlp/article/details/45176129

 1 const max=50001;
 2 var u,c,p:array[0..max] of longint;
 3     g:array[0..max] of int64;
 4     v:array[0..max] of boolean;
 5     i,j,t,n,m:longint;
 6 
 7 function min(a,b:longint):longint;
 8   begin
 9     if a>b then exit(b) else exit(a);
10   end;
11 
12 function cal(n,m:longint):int64;
13   var i,j:longint;
14   begin
15     i:=1;
16     cal:=0;
17     while i<=min(n,m) do
18     begin
19       j:=min(n div (n div i), m div (m div i));
20       cal:=cal+int64(u[j]-u[i-1])*g[n div i]*g[m div i];
21       i:=j+1;
22     end;
23   end;
24 
25 begin
26   u[1]:=1;
27   g[1]:=1;
28   c[1]:=1;
29   for i:=2 to max do
30   begin
31     if not v[i] then
32     begin
33       inc(t);
34       p[t]:=i;
35       g[i]:=2;
36       c[i]:=1;
37       u[i]:=-1;
38     end;
39     for j:=1 to t do
40     begin
41       if i*p[j]>max then break;
42       v[i*p[j]]:=true;
43       if i mod p[j]=0 then
44       begin
45         g[i*p[j]]:=g[i] div (c[i]+1)*int64(c[i]+2);
46         c[i*p[j]]:=c[i]+1;
47         u[i*p[j]]:=0;
48         break;
49       end;
50       g[i*p[j]]:=g[i]*2;
51       u[i*p[j]]:=-u[i];
52       c[i*p[j]]:=1;
53     end;
54   end;
55   for i:=1 to max do
56   begin
57     u[i]:=u[i-1]+u[i];
58     g[i]:=g[i-1]+g[i];
59   end;
60   readln(t);
61   while t>0 do
62   begin
63     dec(t);
64     readln(n,m);
65     writeln(cal(n,m));
66   end;
67 end.
View Code

 

posted on 2015-06-04 22:11  acphile  阅读(263)  评论(0编辑  收藏  举报