1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include <stdio.h> #define n 100000 #define N n + 1 int m; int a[N], b[N], c[N], d[N]; int f[n], g[N]; void init() { f[1] = g[1] = 1; for (int i = 2; i <= n; i++) { if (!a[i]) { b[m++] = i; c[i] = 1, f[i] = 2; d[i] = 1, g[i] = i + 1; } for (int j = 0; j < m && b[j] * i <= n; j++) { int k = b[j]; a[i * k] = 1; if (i % k == 0) { c[i * k] = c[i] + 1; f[i * k] = f[i] / c[i * k] * (c[i * k] + 1); d[i * k] = d[i]; g[i * k] = g[i] * k + d[i]; break; } else { c[i * k] = 1; f[i * k] = 2 * f[i]; d[i * k] = g[i]; g[i * k] = g[i] * (k + 1); } } } } int main() { init(); int x; scanf("%d", &x); printf("%d %d", f[x], g[x]); return 0; } |
假设输入的 x是不超过 1000 的自然数,完成下面的判断题和单选题。
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
28、若输入的不为 “1”,把第 12 行删去不会影响输出的结果。( )
29. 第 24 行的 “f[i] / c[i * k]
” 可能存在无法整除而向下取整的情况。( )
30. 在执行完 init()
后,f
数组不是单调递增的,但 g
数组是单调递增的。( )
init
函数的时间复杂度为( )。
32. 在执行完 init
后,f[1], f[2], f[3]……f[100] 中有( )个等于 2。
33. 当输入为 “1000” 时,输出为( )。