#include <iostream> #include <algorithm> #include <vector> #include <string> #include <random> #include <ctime> using namespace std; const int mod = 1e9 + 7; struct mint { int n; mint(int n_ = 0) : n(n_) {} }; mint operator+(mint a, mint b) { return (a.n += b.n) >= mod ? a.n - mod : a.n; } mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + mod : a.n; } mint operator*(mint a, mint b) { return 1LL * a.n * b.n % mod; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } ostream &operator<<(ostream &o, mint a) { return o << a.n; } int gcd(int x, int y) { while (y != 0) { int r = x % y; x = y; y = r; } return x; } int lcm(int x, int y) { return x / gcd(x, y) * y; } vector<mint> zeta(vector<mint> a) { const int n = a.size(); for (int i = 1; i < n; i++) { for (int j = i * 2; j < n; j += i) { a[i] += a[j]; } } return a; } vector<mint> mobius(vector<mint> a) { const int n = a.size(); for (int i = n - 1; i >= 1; i--) { for (int j = i * 2; j < n; j += i) { a[i] -= a[j]; } } return a; } vector<mint> zeta2(vector<mint> a) { const int n = a.size(); for (int i = n - 1; i >= 1; i--) { for (int j = i * 2; j < n; j += i) { a[j] += a[i]; } } return a; } vector<mint> mobius2(vector<mint> a) { const int n = a.size(); for (int i = 1; i < n; i++) { for (int j = i * 2; j < n; j += i) { a[j] -= a[i]; } } return a; } vector<mint> conv(vector<mint> a, vector<mint> b) { const int n = a.size(); vector<mint> res(n); for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { res[gcd(i, j)] += a[i] * b[j]; } } return res; } vector<mint> conv2(vector<mint> a, vector<mint> b) { const int n = a.size(); vector<mint> res(n); for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { int l = lcm(i, j); if (l < n) { res[l] += a[i] * b[j]; } } } return res; } void solve1() { cout << "gcd" << endl; vector<mint> a(100); for (int i = 1; i < 100; i++) { a[i] = i; } auto ans = conv(a, a); a = zeta(a); for (int i = 1; i < 100; i++) { a[i] *= a[i]; } a = mobius(a); for (int i = 1; i < 100; i++) { cout << i << ' ' << a[i] << ' ' << ans[i] << endl; } cout << endl; } void solve2() { cout << "lcm" << endl; vector<mint> a(100); for (int i = 1; i < 100; i++) { a[i] = i; } auto ans = conv2(a, a); a = zeta2(a); for (int i = 1; i < 100; i++) { a[i] *= a[i]; } a = mobius2(a); for (int i = 1; i < 100; i++) { cout << i << ' ' << a[i] << ' ' << ans[i] << endl; } cout << endl; } int main() { solve1(); solve2(); }
Standard input is empty
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