結果

問題 No.741 AscNumber(Easy)
ユーザー MSK
提出日時 2018-10-10 11:46:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 69,092 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 17:13:03
合計ジャッジ時間 1,943 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

long mod = 1000000007;

long long modpow(long long a, int p) {
  if(p == 0) {
    return 1;
  }
  if(p % 2 == 0) {
    int halfP = p / 2;
    long long half = modpow(a, halfP);
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1) % mod;
  }
}

long long calcComb(int a, int b) {
  if(b > a - b) {
    return calcComb(a, a - b);
  }
  long long ansMul = 1;
  long long ansDiv = 1;
  for(int i = 0; i < b; i++) {
    ansMul *= (a - i);
    ansDiv *= (i + 1);
    ansMul %= mod;
    ansDiv %= mod;
  }
  return ansMul * modpow(ansDiv, mod - 2) % mod;
}

int main(void) {
  int N;
  cin >> N;
  cout << calcComb(N + 9, 9) << endl;
  return 0;
}
0