結果

問題 No.886 Direct
ユーザー niuezniuez
提出日時 2019-09-14 09:05:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 340 ms / 4,000 ms
コード長 2,371 bytes
コンパイル時間 1,617 ms
コンパイル使用メモリ 170,568 KB
実行使用メモリ 75,592 KB
最終ジャッジ日時 2023-09-18 18:42:52
合計ジャッジ時間 6,439 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 111 ms
37,268 KB
testcase_24 AC 126 ms
40,336 KB
testcase_25 AC 62 ms
26,388 KB
testcase_26 AC 96 ms
33,444 KB
testcase_27 AC 302 ms
70,276 KB
testcase_28 AC 277 ms
68,312 KB
testcase_29 AC 332 ms
75,592 KB
testcase_30 AC 328 ms
75,528 KB
testcase_31 AC 333 ms
75,544 KB
testcase_32 AC 330 ms
75,400 KB
testcase_33 AC 327 ms
75,392 KB
testcase_34 AC 340 ms
75,588 KB
testcase_35 AC 334 ms
75,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

template<i64 M>
struct modint {
  i64 a;
  constexpr modint(const i64 x = 0) noexcept: a((x % M + M) % M) {}
  constexpr i64 value() const noexcept { return a; }
  constexpr modint& operator+=(const modint r) noexcept {
    a += r.a;
    if(a >= M) a -= M;
    return *this;
  }
  constexpr modint& operator=(const i64 r) {
    a = (r % M + M) % M;
    return *this;
  }
  constexpr modint& operator-=(const modint r) noexcept {
    a -= r.a;
    if(a < 0) a += M;
    return *this;
  }
  constexpr modint& operator*=(const modint r) noexcept {
    a = a * r.a % M;
    return *this;
  }
  constexpr modint& operator/=(modint r) noexcept {
    i64 ex = M - 2;
    while(ex) {
      if(ex & 1) {
        *this *= r;
      }
      r *= r;
      ex >>= 1;
    }
    return *this;
  }

  constexpr modint operator+(const modint r) const {
    return modint(*this) += r;
  }
  constexpr modint operator-(const modint r) const {
    return modint(*this) -= r;
  }
  constexpr modint operator*(const modint r) const {
    return modint(*this) *= r;
  }
  constexpr modint operator/(const modint r) const {
    return modint(*this) /= r;
  }
};

const i64 mod = 1e9 + 7;

using fp = modint<mod>;


int main() {
  i64 H, W;
  cin >> H >> W;
  i64 N = max(H, W) + 1;
  vector<fp> a(N), b(N);
  rep(i,1,H) a[i] = fp(H - i);
  rep(i,1,W) b[i] = fp(W - i);

  vector<i64> sieve(N, 1);
  vector<i64> prime;
  rep(p,2,N) {
    if(sieve[p]) {
      prime.push_back(p);
      for(i64 k = 1;k * p < N; ++k) {
        sieve[k * p] = false;
      }
    }
  }

  for(auto p: prime) {
    for(i64 i = (N - 1) / p; i > 0; i--) {
      a[i] += a[i * p];
      b[i] += b[i * p];
    }
  }
  for(i64 i = 1;i < N;i++) a[i] *= b[i];
  for(auto p: prime) {
    i64 m = (N - 1) / p;
    for(i64 i = 1; i <= m; i++) {
      a[i] -= a[i * p];
    }
  }

  cout << (a[1] * fp(2) + fp(H * (W - 1) + W * (H - 1))).value() << endl;
}
0