結果

問題 No.391 CODING WAR
ユーザー ayanamizutaayanamizuta
提出日時 2017-09-25 00:34:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 55,124 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 17:53:00
合計ジャッジ時間 1,371 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

#define LL long long
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)

LL pow(LL n, LL m){
  LL a = 1;
  LL i,prod;
  prod=n;
  while(m > 0){
    if(m % 2 == 1)
      a = a*prod % MOD;
    prod = prod*prod %MOD;
    m /= 2;
  }
  return a;
}

LL ans(LL n, LL m){
  LL val = pow(m,n);
  LL i;
  LL com = 1;
  FOR(i,1,m){
    com = (com*(m-i+1)/i) % MOD;
    val = (m-i)%2==0 ? (val + com*pow(i,n)) % MOD : (MOD + (val - com*pow(i,n)) % MOD) % MOD;
  }
  return val;
}

int main(){
  LL n,m;
  cin >> n >> m;
  if(n >= m)
    cout << ans(n,m) << endl;
  else
    cout << 0 << endl;
  return 0;
}
0