1 /*七夕节
2 如果N=p_1^n_1*p_2^n2*......*p_m^n_m
3 则结果为(p_1^0+p_1^1+...+p_1^n_1)*(p_2^0+p_2^1+...+p_2^n_2)*...*(p_m^0+p_m^1+...+p_m^n_m)-N
4 */
5 #include<iostream>
6 #include<string.h>
7 #include<stdio.h>
8 using namespace std;
9 int prime[500000], cnt, n, ans;
10 bool primtmp[500002];
11 int main()
12 {
13 cnt = 0;
14 memset(primtmp, -1, sizeof(primtmp));
15 for (int i = 2; i <= 500000; ++i) {
16 if (primtmp[i]) {
17 prime[cnt++] = i;
18 int p = 2 * i;
19 while (p <= 500000) {
20 primtmp[p] = 0;
21 p += i;
22 }
23 }
24 }
25 int T;
26 scanf("%d", &T);
27 while (T--) {
28 scanf("%d", &n);
29 int N = n, pos = 0;
30 ans = 1;
31 while (n > 1) {
32 int ps = 1;
33 while (n % prime[pos] == 0) {
34 n /= prime[pos];
35 ps *= prime[pos];
36 ps++;
37 }
38 ans *= ps;
39 pos++;
40 }
41 printf("%d\n", ans - N);
42 }
43 }
2 如果N=p_1^n_1*p_2^n2*......*p_m^n_m
3 则结果为(p_1^0+p_1^1+...+p_1^n_1)*(p_2^0+p_2^1+...+p_2^n_2)*...*(p_m^0+p_m^1+...+p_m^n_m)-N
4 */
5 #include<iostream>
6 #include<string.h>
7 #include<stdio.h>
8 using namespace std;
9 int prime[500000], cnt, n, ans;
10 bool primtmp[500002];
11 int main()
12 {
13 cnt = 0;
14 memset(primtmp, -1, sizeof(primtmp));
15 for (int i = 2; i <= 500000; ++i) {
16 if (primtmp[i]) {
17 prime[cnt++] = i;
18 int p = 2 * i;
19 while (p <= 500000) {
20 primtmp[p] = 0;
21 p += i;
22 }
23 }
24 }
25 int T;
26 scanf("%d", &T);
27 while (T--) {
28 scanf("%d", &n);
29 int N = n, pos = 0;
30 ans = 1;
31 while (n > 1) {
32 int ps = 1;
33 while (n % prime[pos] == 0) {
34 n /= prime[pos];
35 ps *= prime[pos];
36 ps++;
37 }
38 ans *= ps;
39 pos++;
40 }
41 printf("%d\n", ans - N);
42 }
43 }