結果
| 問題 |
No.487 2017 Calculation(2017の計算)
|
| コンテスト | |
| ユーザー |
anta
|
| 提出日時 | 2017-02-24 22:23:11 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,410 bytes |
| コンパイル時間 | 1,978 ms |
| コンパイル使用メモリ | 161,948 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-02 22:36:48 |
| 合計ジャッジ時間 | 2,152 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }
struct GModInt {
static int Mod;
unsigned x;
GModInt() : x(0) { }
GModInt(signed sig) { int sigt = sig % Mod; if (sigt < 0) sigt += Mod; x = sigt; }
GModInt(signed long long sig) { int sigt = sig % Mod; if (sigt < 0) sigt += Mod; x = sigt; }
int get() const { return (int)x; }
GModInt &operator+=(GModInt that) { if ((x += that.x) >= (unsigned)Mod) x -= Mod; return *this; }
GModInt &operator-=(GModInt that) { if ((x += Mod - that.x) >= (unsigned)Mod) x -= Mod; return *this; }
GModInt &operator*=(GModInt that) { x = (unsigned long long)x * that.x % Mod; return *this; }
GModInt &operator/=(GModInt that) { return *this *= that.inverse(); }
GModInt operator+(GModInt that) const { return GModInt(*this) += that; }
GModInt operator-(GModInt that) const { return GModInt(*this) -= that; }
GModInt operator*(GModInt that) const { return GModInt(*this) *= that; }
GModInt operator/(GModInt that) const { return GModInt(*this) /= that; }
//Modと素であることが保証されるかどうか確認すること!
GModInt inverse() const {
signed a = x, b = Mod, u = 1, v = 0;
while (b) {
signed t = a / b;
a -= t * b; std::swap(a, b);
u -= t * v; std::swap(u, v);
}
if (u < 0) u += Mod;
GModInt res; res.x = (unsigned)u;
return res;
}
bool operator==(GModInt that) const { return x == that.x; }
bool operator!=(GModInt that) const { return x != that.x; }
GModInt operator-() const { GModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
int GModInt::Mod = 0;
typedef GModInt mint;
mint operator^(mint a, unsigned long long k) {
mint r = 1;
while (k) {
if (k & 1) r *= a;
a *= a;
k >>= 1;
}
return r;
}
int main() {
int M;
while (~scanf("%d", &M)) {
mint::Mod = M;
mint ans = mint(2017) + (mint(2017 * 2017) ^ 2017);
printf("%d\n", ans.get());
}
return 0;
}
anta