結果
| 問題 | No.1258 コインゲーム | 
| コンテスト | |
| ユーザー |  ocvret_ | 
| 提出日時 | 2020-10-16 22:36:32 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 264 ms / 2,000 ms | 
| コード長 | 726 bytes | 
| コンパイル時間 | 1,444 ms | 
| コンパイル使用メモリ | 166,932 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-20 22:55:58 | 
| 合計ジャッジ時間 | 11,513 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 50 | 
ソースコード
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
ll modpow(ll n,ll r){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}
int main(){
  
  int T;
  cin >> T;
  while(T--){
    int n,m,x;
    cin >> n >> m >> x;
    if((x & 1) == (n & 1)){
      cout << ((modpow(m-1,n)+modpow(m+1,n))%MOD)*modpow(2,MOD-2)%MOD << "\n";
    }else{
      cout << (MOD-modpow(m-1,n)+modpow(m+1,n))%MOD*modpow(2,MOD-2)%MOD << "\n";
    }
  }
  return 0;
}
            
            
            
        