結果
問題 | No.1258 コインゲーム |
ユーザー |
![]() |
提出日時 | 2020-10-16 22:50:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 277 ms / 2,000 ms |
コード長 | 609 bytes |
コンパイル時間 | 1,821 ms |
コンパイル使用メモリ | 194,360 KB |
最終ジャッジ日時 | 2025-01-15 09:04:48 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const ll MOD=1e9+7; const ll A=500000004; ll modpow(ll x,ll n){ ll ans=1; while(n){ if(n&1) ans=ans*x %MOD; x=x*x %MOD; n/=2; } return ans; } int main(){ int s; cin>>s; while(s--){ ll n,m; int x; cin>>n>>m>>x; if(x==0){ cout<<(modpow(1+m,n)+modpow((1-m+MOD)%MOD,n))*A%MOD<<endl; } else{ cout<<((modpow(1+m,n)-modpow((1-m+MOD)%MOD,n)+MOD)%MOD)*A%MOD<<endl; } } return 0; }