結果

問題 No.1164 GCD Products hard
ユーザー MisterMister
提出日時 2020-08-18 06:09:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,670 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 76,004 KB
実行使用メモリ 42,240 KB
最終ジャッジ日時 2024-04-19 22:37:15
合計ジャッジ時間 43,929 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,779 ms
30,208 KB
testcase_01 AC 2,238 ms
33,152 KB
testcase_02 AC 1,484 ms
25,344 KB
testcase_03 AC 423 ms
10,660 KB
testcase_04 AC 405 ms
11,220 KB
testcase_05 AC 1,891 ms
29,664 KB
testcase_06 AC 2,317 ms
35,200 KB
testcase_07 AC 2,391 ms
36,992 KB
testcase_08 AC 2,196 ms
36,736 KB
testcase_09 AC 1,439 ms
26,440 KB
testcase_10 AC 422 ms
9,984 KB
testcase_11 AC 1,607 ms
27,904 KB
testcase_12 AC 2,432 ms
34,944 KB
testcase_13 AC 1,245 ms
22,312 KB
testcase_14 AC 1,220 ms
25,988 KB
testcase_15 AC 2,473 ms
37,376 KB
testcase_16 AC 1,415 ms
28,116 KB
testcase_17 AC 1,876 ms
28,928 KB
testcase_18 AC 1,539 ms
26,704 KB
testcase_19 AC 449 ms
11,776 KB
testcase_20 AC 787 ms
15,828 KB
testcase_21 TLE -
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2,388 ms
42,112 KB
testcase_24 TLE -
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    bool operator<(const ModInt& b) const { return val < b.val; }
    bool operator<=(const ModInt& b) const { return val <= b.val; }
    bool operator>(const ModInt& b) const { return val > b.val; }
    bool operator>=(const ModInt& b) const { return val >= b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept {
        lint v;
        is >> v;
        x = v;
        return is;
    }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;
using smint = ModInt<MOD - 1>;

void solve() {
    int l, r, n;
    std::cin >> l >> r >> n;

    std::vector<smint> cnt(r + 1);
    for (int g = r; g >= 1; --g) {
        cnt[g] = smint(r / g - (l - 1) / g).pow(n);
        for (int p = g * 2; p <= r; p += g) {
            cnt[g] -= cnt[p];
        }
    }

    mint ans = 1;
    for (int g = 1; g <= r; ++g) {
        ans *= mint(g).pow(cnt[g].val);
    }
    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0