题意:求1~n的素因子之和。
分析:欧拉函数
1 #include<cstdio> 2 #include<cstring> 3 #include<cctype> 4 #include<cstdlib> 5 #include<cmath> 6 #include<iostream> 7 #include<sstream> 8 #include<iterator> 9 #include<algorithm> 10 #include<string> 11 #include<vector> 12 #include<set> 13 #include<map> 14 #include<deque> 15 #include<queue> 16 #include<stack> 17 #include<list> 18 #define fin freopen("in.txt", "r", stdin) 19 #define fout freopen("out.txt", "w", stdout) 20 #define pr(x) cout << #x << " : " << x << " " 21 #define prln(x) cout << #x << " : " << x << endl 22 typedef long long ll; 23 typedef unsigned long long llu; 24 const int INT_INF = 0x3f3f3f3f; 25 const int INT_M_INF = 0x7f7f7f7f; 26 const ll LL_INF = 0x3f3f3f3f3f3f3f3f; 27 const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f; 28 const double pi = acos(-1.0); 29 const double EPS = 1e-6; 30 const int dx[] = {0, 0, -1, 1}; 31 const int dy[] = {-1, 1, 0, 0}; 32 const ll MOD = 1e9 + 7; 33 const int MAXN = 10000 + 10; 34 const int MAXT = 10000 + 10; 35 using namespace std; 36 int pr[MAXN]; 37 int ps[MAXN]; 38 void init() 39 { 40 for(int i = 2; i <= 10000; ++i) 41 { 42 int tmp1 = i; 43 int tmp2 = i; 44 for(int j = 2; j <= i; ++j) 45 if(tmp2 % j == 0) 46 { 47 tmp1 = tmp1 / j * (j - 1); 48 tmp2 /= j; 49 while(!(tmp2 % j)) 50 tmp2 /= j; 51 } 52 pr[i] = tmp1; 53 } 54 ps[1] = 2; 55 for(int i = 2; i <= 10000; ++i) 56 ps[i] = ps[i - 1] + pr[i]; 57 } 58 int main() 59 { 60 int P; 61 scanf("%d", &P); 62 init(); 63 while(P--) 64 { 65 int x, n; 66 scanf("%d%d", &x, &n); 67 printf("%d %d\n", x, ps[n]); 68 } 69 return 0; 70 }