結果

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

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll pw(ll a,ll x){
    ll ret = 1; a %= mod;
    while(x){
        if(x&1) (ret *= a) %= mod;
        x /= 2; (a *= a) %= mod;
    }
    return ret;
}

int main(){
    ll n,k,inv = (mod + 1)/2; cin >> n >> k;
    k %= mod;
    ll ans = (pw((k + 3)%mod*k%mod*inv%mod,n) - pw((k + 1)%mod*k%mod*inv%mod,n) + mod)%mod;
    cout << ans << endl;
}
0