結果
| 問題 |
No.487 2017 Calculation(2017の計算)
|
| コンテスト | |
| ユーザー |
noynote
|
| 提出日時 | 2017-02-24 22:29:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,181 bytes |
| コンパイル時間 | 1,865 ms |
| コンパイル使用メモリ | 156,724 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-01-02 22:53:58 |
| 合計ジャッジ時間 | 2,744 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#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;
}
noynote