結果
問題 |
No.1258 コインゲーム
|
ユーザー |
![]() |
提出日時 | 2020-10-17 04:06:40 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 514 ms / 2,000 ms |
コード長 | 1,022 bytes |
コンパイル時間 | 1,213 ms |
コンパイル使用メモリ | 84,440 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-21 01:47:58 |
合計ジャッジ時間 | 17,826 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); ll mypow(ll a, ll b) { ll ans = 1; ll two; ll tmp; while(b>0) { two = 1; tmp = a; while(2*two<b) { two *= 2; tmp *= tmp; tmp %= mod; } b -= two; ans *= tmp; ans %= mod; } return ans; } int main() { int S; cin>>S; ll ans[S]; ll N, M, X; for(int i=0;i<S;++i) { cin>>N>>M>>X; if(X==1) ans[i] = (mypow(1+M, N)-mypow(1-M+mod, N)+mod)%mod*mypow(2, mod-2)%mod; else ans[i] = (mypow(1+M, N)+mypow(1-M+mod, N))%mod*mypow(2, mod-2)%mod; } for(int i=0;i<S;++i) cout<<ans[i]<<endl; }