結果

問題 No.487 2017 Calculation(2017の計算)
ユーザー noynotenoynote
提出日時 2017-02-24 22:29:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,181 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 144,676 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 23:24:14
合計ジャッジ時間 1,977 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;


/*
   べき乗
   x^n mod M
   */
typedef unsigned long long ull;
ull power(ull x, ull n, ull M){
    ull res = 1;
    if(n > 0){
        res = power(x, n / 2, M);
        if(n % 2 == 0) res = (res * res) % M;
        else res = (((res * res) % M) * x ) % M;
    }
    return res;
}

//階乗
ull factorial(int n, ull M){
    ull res = 1;
    range(i,1,n + 1){
        res*= i;
        res%= M;
    }
    return res;
}

/*
   nCr コンビネーション
   (1,1)から(w,h)だと、引数は(w - 1, h - 1, M)
   */
ull combination(ull w, ull h, ull M){
    //nCr = n! / ( (n - r)! * r! )
    ull a = factorial(w + h, M);
    ull b = factorial(h, M) * factorial(w, M) % M;
    return a * power(b, M - 2, M) % M;
}

int main(){
    ull m;
    cin >> m;
    cout << (2017 + power(2017 * 2017, 2017, m)) % m << endl;
}
0