結果

問題 No.391 CODING WAR
ユーザー ei1333333ei1333333
提出日時 2016-07-08 23:57:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 1,192 ms
コンパイル使用メモリ 144,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-03 10:50:28
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

long long mod_pow(long long a,long long b,long long mod)
{
  if( b == 0 ) return 1;
  long long res = mod_pow(a*a%mod,b/2,mod);
  if( b&1 ) res = (res * a)%mod;
  return res;
} 
long long inv(long long a,long long mod)
{
  return mod_pow(a, mod - 2, mod);
}

int main()
{
  long long N, K;
  cin >> N >> K;
  long long ret = 0;
  long long comb = 1, poyo = K;
  for(int i = 1; i <= K; i++) {
    long long sign = pow(-1, K - i);
    comb *= poyo--;
    comb %= MOD;
    comb *= inv(i, MOD);
    comb %= MOD;
    (ret += sign * comb * mod_pow(i, N, MOD) + MOD) %= MOD;
  }
  cout << ret << endl;
}
0