bzoj 2749: [HAOI2012]外星人

Description

 

Input

 

Output

输出test行,每行一个整数,表示答案。

Sample Input

1
2
2 2
3 1

Sample Output

3

HINT

Test<=50 Pi<=10^5,1<=Q1<=10^9

 

 1 #include<iostream>
 2 #include<cstdio>
 3 #define ll long long
 4 using namespace std;
 5  
 6 int m,n,cnt,f[100005],c[100005];
 7 void pfs(){
 8     int i,j; f[1]=1;
 9     for (i=2; i<=100000; i++){
10         if (!f[i]){ c[++cnt]=i; f[i]=f[i-1]; }
11         for (j=1; j<=cnt; j++){
12             if (i*c[j]>100000) break;
13             f[i*c[j]]=f[i]+f[c[j]];
14             if (!(i%c[j])) break;
15         }
16     }
17 }
18 int main(){
19     int cas; scanf("%d",&cas); pfs();
20     while (cas--){
21         scanf("%d",&n); int i,flag=1; ll ans=0;
22         for (i=1; i<=n; i++){
23             int x,y; scanf("%d%d",&x,&y);
24             flag&=x&1; ans+=(ll)f[x]*y;
25         }
26         printf("%lld\n",ans+(ll)flag);
27     }
28     return 0;
29 }
View Code

猜你喜欢

转载自www.cnblogs.com/ZJXXCN/p/11505031.html
今日推荐