标签:
1 #include <cstdio> 2 3 int f[100010], phi[100010], two[100010]; 4 int test, n, a, b, flag; 5 long long ans, maxans; 6 7 int main() 8 { 9 for (int i = 2; i < 100000; i++) 10 { 11 if (f[i]) continue; 12 phi[i] = i - 1; 13 for (int j = i + i; j < 100000; j += i) 14 { 15 f[j] = 1; 16 if (phi[j] == 0) phi[j] = j; 17 phi[j] = phi[j] / i * (i - 1); 18 } 19 } 20 for (int i = 2; i < 100000; i++) 21 { 22 if (i % 2 == 0) two[i] = two[i / 2] + 1; 23 else two[i] = two[phi[i]]; 24 } 25 scanf("%d", &test); 26 maxans = 0; 27 while (test--) 28 { 29 scanf("%d", &n); 30 ans = flag = 0; 31 while (n--) 32 { 33 scanf("%d %d", &a, &b); 34 if (a == 2) flag = 1; 35 ans += (long long) two[a] * b; 36 } 37 ans = ans - flag + 1; 38 printf("%lld\n", ans); 39 if (ans > maxans) maxans = ans; 40 } 41 printf("%lld", maxans); 42 }
标签:
原文地址:http://www.cnblogs.com/lightning34/p/4600863.html