結果

問題 No.1181 Product Sum for All Subsets
ユーザー t33ft33f
提出日時 2020-08-21 21:57:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 475 bytes
コンパイル時間 530 ms
コンパイル使用メモリ 63,872 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-15 05:36:53
合計ジャッジ時間 1,426 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int M = 1000000007;
long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

int main() {
    long long n, k; cin >> n >> k;
    k %= M;
    cout << ((modexp(((k + 1) * (k + 2) / 2 - 1) % M, n, M)
              - modexp(k * (k + 1) / 2 % M, n, M)) % M + M) % M << endl;
}
0