fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. #include <random>
  6. #include <ctime>
  7.  
  8. using namespace std;
  9.  
  10. const int mod = 1e9 + 7;
  11.  
  12. struct mint {
  13. int n;
  14. mint(int n_ = 0) : n(n_) {}
  15. };
  16.  
  17. mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; }
  18. mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; }
  19. mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; }
  20. mint &operator+=(mint &a, mint b) { return a = a + b; }
  21. mint &operator-=(mint &a, mint b) { return a = a - b; }
  22. mint &operator*=(mint &a, mint b) { return a = a * b; }
  23. ostream &operator<<(ostream &o, mint a) { return o << a.n; }
  24.  
  25. int gcd(int x, int y) {
  26. while (y != 0) {
  27. int r = x % y;
  28. x = y;
  29. y = r;
  30. }
  31. return x;
  32. }
  33.  
  34. int lcm(int x, int y) {
  35. return x / gcd(x, y) * y;
  36. }
  37.  
  38.  
  39. vector<mint> zeta(vector<mint> a) {
  40. const int n = a.size();
  41. for (int i = 1; i < n; i++) {
  42. for (int j = i * 2; j < n; j += i) {
  43. a[i] += a[j];
  44. }
  45. }
  46. return a;
  47. }
  48.  
  49. vector<mint> mobius(vector<mint> a) {
  50. const int n = a.size();
  51. for (int i = n - 1; i >= 1; i--) {
  52. for (int j = i * 2; j < n; j += i) {
  53. a[i] -= a[j];
  54. }
  55. }
  56. return a;
  57. }
  58.  
  59. vector<mint> zeta2(vector<mint> a) {
  60. const int n = a.size();
  61. for (int i = n - 1; i >= 1; i--) {
  62. for (int j = i * 2; j < n; j += i) {
  63. a[j] += a[i];
  64. }
  65. }
  66. return a;
  67. }
  68.  
  69. vector<mint> mobius2(vector<mint> a) {
  70. const int n = a.size();
  71. for (int i = 1; i < n; i++) {
  72. for (int j = i * 2; j < n; j += i) {
  73. a[j] -= a[i];
  74. }
  75. }
  76. return a;
  77. }
  78.  
  79. vector<mint> conv(vector<mint> a, vector<mint> b) {
  80. const int n = a.size();
  81. vector<mint> res(n);
  82. for (int i = 1; i < n; i++) {
  83. for (int j = 1; j < n; j++) {
  84. res[gcd(i, j)] += a[i] * b[j];
  85. }
  86. }
  87. return res;
  88. }
  89.  
  90. vector<mint> conv2(vector<mint> a, vector<mint> b) {
  91. const int n = a.size();
  92. vector<mint> res(n);
  93. for (int i = 1; i < n; i++) {
  94. for (int j = 1; j < n; j++) {
  95. int l = lcm(i, j);
  96. if (l < n) {
  97. res[l] += a[i] * b[j];
  98. }
  99. }
  100. }
  101. return res;
  102. }
  103.  
  104. void solve1() {
  105. cout << "gcd" << endl;
  106. vector<mint> a(100);
  107. for (int i = 1; i < 100; i++) {
  108. a[i] = i;
  109. }
  110. auto ans = conv(a, a);
  111. a = zeta(a);
  112. for (int i = 1; i < 100; i++) {
  113. a[i] *= a[i];
  114. }
  115. a = mobius(a);
  116. for (int i = 1; i < 100; i++) {
  117. cout << i << ' ' << a[i] << ' ' << ans[i] << endl;
  118. }
  119. cout << endl;
  120. }
  121.  
  122. void solve2() {
  123. cout << "lcm" << endl;
  124. vector<mint> a(100);
  125. for (int i = 1; i < 100; i++) {
  126. a[i] = i;
  127. }
  128. auto ans = conv2(a, a);
  129. a = zeta2(a);
  130. for (int i = 1; i < 100; i++) {
  131. a[i] *= a[i];
  132. }
  133. a = mobius2(a);
  134. for (int i = 1; i < 100; i++) {
  135. cout << i << ' ' << a[i] << ' ' << ans[i] << endl;
  136. }
  137. cout << endl;
  138. }
  139.  
  140. int main() {
  141. solve1();
  142. solve2();
  143. }
  144.  
  145.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
gcd
1 14844947 14844947
2 3736460 3736460
3 1746261 1746261
4 850320 850320
5 589175 589175
6 378036 378036
7 325997 325997
8 220736 220736
9 232713 232713
10 126300 126300
11 152823 152823
12 111888 111888
13 88049 88049
14 102116 102116
15 51075 51075
16 58112 58112
17 44795 44795
18 50220 50220
19 55955 55955
20 22000 22000
21 24255 24255
22 26620 26620
23 29095 29095
24 31680 31680
25 14375 14375
26 15548 15548
27 16767 16767
28 18032 18032
29 19343 19343
30 20700 20700
31 22103 22103
32 23552 23552
33 25047 25047
34 5780 5780
35 6125 6125
36 6480 6480
37 6845 6845
38 7220 7220
39 7605 7605
40 8000 8000
41 8405 8405
42 8820 8820
43 9245 9245
44 9680 9680
45 10125 10125
46 10580 10580
47 11045 11045
48 11520 11520
49 12005 12005
50 2500 2500
51 2601 2601
52 2704 2704
53 2809 2809
54 2916 2916
55 3025 3025
56 3136 3136
57 3249 3249
58 3364 3364
59 3481 3481
60 3600 3600
61 3721 3721
62 3844 3844
63 3969 3969
64 4096 4096
65 4225 4225
66 4356 4356
67 4489 4489
68 4624 4624
69 4761 4761
70 4900 4900
71 5041 5041
72 5184 5184
73 5329 5329
74 5476 5476
75 5625 5625
76 5776 5776
77 5929 5929
78 6084 6084
79 6241 6241
80 6400 6400
81 6561 6561
82 6724 6724
83 6889 6889
84 7056 7056
85 7225 7225
86 7396 7396
87 7569 7569
88 7744 7744
89 7921 7921
90 8100 8100
91 8281 8281
92 8464 8464
93 8649 8649
94 8836 8836
95 9025 9025
96 9216 9216
97 9409 9409
98 9604 9604
99 9801 9801

lcm
1 1 1
2 8 8
3 15 15
4 40 40
5 35 35
6 120 120
7 63 63
8 176 176
9 153 153
10 280 280
11 143 143
12 600 600
13 195 195
14 504 504
15 525 525
16 736 736
17 323 323
18 1224 1224
19 399 399
20 1400 1400
21 945 945
22 1144 1144
23 575 575
24 2640 2640
25 925 925
26 1560 1560
27 1431 1431
28 2520 2520
29 899 899
30 4200 4200
31 1023 1023
32 3008 3008
33 2145 2145
34 2584 2584
35 2205 2205
36 6120 6120
37 1443 1443
38 3192 3192
39 2925 2925
40 6160 6160
41 1763 1763
42 7560 7560
43 1935 1935
44 5720 5720
45 5355 5355
46 4600 4600
47 2303 2303
48 11040 11040
49 3185 3185
50 7400 7400
51 4845 4845
52 7800 7800
53 2915 2915
54 11448 11448
55 5005 5005
56 11088 11088
57 5985 5985
58 7192 7192
59 3599 3599
60 21000 21000
61 3843 3843
62 8184 8184
63 9639 9639
64 12160 12160
65 6825 6825
66 17160 17160
67 4623 4623
68 12920 12920
69 8625 8625
70 17640 17640
71 5183 5183
72 26928 26928
73 5475 5475
74 11544 11544
75 13875 13875
76 15960 15960
77 9009 9009
78 23400 23400
79 6399 6399
80 25760 25760
81 13041 13041
82 14104 14104
83 7055 7055
84 37800 37800
85 11305 11305
86 15480 15480
87 13485 13485
88 25168 25168
89 8099 8099
90 42840 42840
91 12285 12285
92 23000 23000
93 15345 15345
94 18424 18424
95 13965 13965
96 45120 45120
97 9603 9603
98 25480 25480
99 21879 21879