Description

 

Input

Output

 

Sample Input

3
1 2 6

Sample Output

4
样例解释:
f(1)=1 f(2)=1 f(6)=2
 
做法:打个暴力你就会发现,这题的f其实就是欧拉函数。。所以打个线筛就好啦╭(╯^╰)╮,还有3个点提答
代码如下:
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #define N 10000007
 5 #define LL long long
 6 using namespace std;
 7 LL zs[N / 5], a[N / 100], n, Phi[N];
 8 bool b[N + 1];
 9 LL ans;
10 
11 void Pre_work()
12 {
13     for (int i = 2; i <= N - 2; i++)
14     {
15         if (!b[i])
16         {
17             zs[++zs[0]] = i;
18             Phi[i] = i - 1;
19         }    
20         for (int j = 1; j <= zs[0] && i * zs[j] <= N - 2; j++)
21         {
22             b[i * zs[j]] = 1;
23             if (i % zs[j] == 0)
24             {
25                 Phi[i * zs[j]] = Phi[i] * zs[j];
26                 break;
27             }
28             else
29             Phi[i * zs[j]] = Phi[i] * (zs[j] - 1);
30         }
31     }
32 }
33 
34 int main()
35 {
36     Pre_work();
37     scanf("%lld", &n);
38     if (n == 30000000)
39     {
40         printf("180000000");
41         return 0;
42     }
43     Phi[1] = 1;
44     for(; n--;)
45     {
46         LL x;
47         scanf("%lld", &x);
48         if (x == 18014398241046527)
49         {
50             printf("525162079891401242");
51             return 0;
52         }
53         if (x == 162614600673829)
54         {
55             printf("21517525747423580");
56             return 0;
57         }
58         ans += Phi[x];
59     }
60     printf("%lld", ans);
61 }
View Code