結果

問題 No.1181 Product Sum for All Subsets
ユーザー merom686merom686
提出日時 2020-08-21 22:32:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 723 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 89,776 KB
最終ジャッジ日時 2025-01-13 06:16:20
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2);
}

int main() {
    int n;
    ll k;
    cin >> n >> k;

    ll t = k % P * ((k + 1) % P) % P * modinv(2) % P;
    t = powmod(t, n);
    ll s = ((k + 1) % P * ((k + 2) % P) % P * modinv(2) + P - 1) % P;
    s = powmod(s, n);

    s -= t;
    s %= P;
    if (s < 0) s += P;

    cout << s << endl;

    return 0;
}
0