結果

問題 No.886 Direct
ユーザー ゆきのんゆきのん
提出日時 2019-09-26 15:38:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 377 ms / 4,000 ms
コード長 1,687 bytes
コンパイル時間 2,729 ms
コンパイル使用メモリ 172,536 KB
実行使用メモリ 73,912 KB
最終ジャッジ日時 2023-10-24 15:22:06
合計ジャッジ時間 6,948 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 91 ms
28,884 KB
testcase_24 AC 116 ms
35,588 KB
testcase_25 AC 57 ms
21,176 KB
testcase_26 AC 71 ms
25,416 KB
testcase_27 AC 279 ms
60,156 KB
testcase_28 AC 259 ms
59,296 KB
testcase_29 AC 240 ms
50,668 KB
testcase_30 AC 234 ms
50,668 KB
testcase_31 AC 377 ms
73,912 KB
testcase_32 AC 377 ms
73,912 KB
testcase_33 AC 375 ms
73,912 KB
testcase_34 AC 363 ms
73,912 KB
testcase_35 AC 357 ms
73,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;

template <class T> void multiple_transform(::std::vector<T> &a) {
    int n = a.size();
    ::std::vector<bool> sieve(n, true);
    for (int p = 2; p < n; ++p) {
        if (sieve[p]) {
            for (int k = (n - 1) / p; k != 0; --k) {
                sieve[k * p] = false;
                a[k] = (a[k] + a[k * p])%mod;
            }
        }
    }
    for (int i = 0; ++i != n;) {
        a[i] = (a[i] + a[0])%mod;
    }
}

template <class T> void inverse_multiple_transform(::std::vector<T> &a) {
    int n = a.size();
    ::std::vector<bool> sieve(n, true);
    for (int i = 0; ++i != n;) {
        a[i] = (a[i] - a[0] + mod)%mod;
    }
    for (int p = 2; p < n; ++p) {
        if (sieve[p]) {
            for (int k = 1; k * p < n; ++k) {
                sieve[k * p] = false;
                a[k] = (a[k] - a[k * p] + mod)%mod;
            }
        }
    }
}


int main(){
    LL h,w;cin >> h >> w;
    vector<LL> a(h+1),b(w+1);
    for (int i = 1; i <= h; i++) {
        a[i] = h - i;
    }
    multiple_transform(a);
    for (int i = 1; i <= w; i++) {
        b[i] = w - i;
    }
    multiple_transform(b);
    vector<LL> c(max(h,w)+1,0);
    for (int i = 1; i <= min(h,w); i++) {
        c[i] = (a[i] * b[i])%mod;
    }
    inverse_multiple_transform(c);
    cout << ((h*(w-1)%mod) + (w*(h-1) %mod) + 2 * c[1])%mod << endl;
    return 0;
}

0