結果
問題 | No.886 Direct |
ユーザー | drken1215 |
提出日時 | 2019-10-01 12:11:39 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 186 ms / 4,000 ms |
コード長 | 4,073 bytes |
コンパイル時間 | 649 ms |
コンパイル使用メモリ | 77,728 KB |
実行使用メモリ | 97,456 KB |
最終ジャッジ日時 | 2024-10-03 05:40:26 |
合計ジャッジ時間 | 3,361 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 1 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 1 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,816 KB |
testcase_09 | AC | 1 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 1 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 1 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | AC | 3 ms
6,820 KB |
testcase_18 | AC | 3 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,816 KB |
testcase_21 | AC | 3 ms
6,820 KB |
testcase_22 | AC | 3 ms
6,816 KB |
testcase_23 | AC | 77 ms
47,660 KB |
testcase_24 | AC | 81 ms
51,788 KB |
testcase_25 | AC | 49 ms
33,076 KB |
testcase_26 | AC | 62 ms
42,596 KB |
testcase_27 | AC | 165 ms
90,564 KB |
testcase_28 | AC | 165 ms
87,776 KB |
testcase_29 | AC | 178 ms
97,336 KB |
testcase_30 | AC | 184 ms
97,348 KB |
testcase_31 | AC | 178 ms
97,456 KB |
testcase_32 | AC | 186 ms
97,408 KB |
testcase_33 | AC | 181 ms
97,312 KB |
testcase_34 | AC | 183 ms
97,296 KB |
testcase_35 | AC | 176 ms
97,252 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) v += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept { return is >> x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; // f(k) = sum_{GCD(i, j) = k} g(i)h(j) // F(k) = sum_{k | i} f(i) template<class T> struct FastGCDConvolution { int N; vector<bool> is_prime; FastGCDConvolution(int N) : N(N), is_prime(N, true) { is_prime[0] = is_prime[1] = false; for (int p = 2; p < N; ++p) { if (!is_prime[p]) continue; for (int i = p*2; i < N; i += p) is_prime[i] = false; } } void zeta(vector<T> &v) { for (int p = 2; p < N; ++p) { if (!is_prime[p]) continue; for (int i = (N-1)/p; i >= 1; --i) v[i] += v[i*p]; } } void mebius(vector<T> &v) { for (int p = 2; p < N; ++p) { if (!is_prime[p]) continue; for (int i = 1; i*p < N; ++i) v[i] -= v[i*p]; } } vector<T> mult(vector<T> &a, vector<T> &b) { vector<T> c(N); zeta(a); zeta(b); for (int i = 1; i < N; ++i) c[i] = a[i] * b[i]; mebius(c); return c; } }; using mint = Fp<1000000007>; int main() { int H, W; cin >> H >> W; mint res = mint(H) * (W-1) + mint(W) * (H-1); int N = max(H, W); vector<mint> h(N, 0), w(N, 0), f(N, 0); for (int i = 1; i < H; ++i) h[i] = H - i; for (int i = 1; i < W; ++i) w[i] = W - i; FastGCDConvolution<mint> fz(N); f = fz.mult(h, w); res += f[1] * 2; cout << res << endl; }