根绝欧拉函数的计算式,欧拉函数次方每次就是不断把2消掉,并把其他质因子不断变出2,最终弄成1
显然我们先预处理每个数会被弄出多少个2出来,次方=弄出来的2的总数-[一开始是否有2]
(因为一开始没2的话是要先次方一下,无法消掉1个2)

 1 var p,w:array[0..100010] of longint;
 2     f:array[0..100010] of boolean;
 3     t,i,j,n,x,y:longint;
 4     ans:int64;
 5     ch:boolean;
 6 
 7 begin
 8   w[1]:=1;
 9   for i:=2 to 100000 do
10   begin
11     if w[i]=0 then
12     begin
13       inc(t);
14       p[t]:=i;
15       w[i]:=w[i-1];
16     end;
17     for j:=1 to t do
18     begin
19       if i*p[j]>100000 then break;
20       w[i*p[j]]:=w[i]+w[p[j]];
21       if i mod p[j]=0 then break;
22     end;
23   end;
24   readln(t);
25   while t>0 do
26   begin
27     dec(t);
28     readln(n);
29     ans:=1;
30     for i:=1 to n do
31     begin
32       readln(x,y);
33       if x=2 then dec(ans);
34       ans:=ans+int64(w[x])*int64(y);
35     end;
36     writeln(ans);
37   end;
38 end.
View Code

 

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