結果
問題 | No.1161 Many Powers |
ユーザー | ningenMe |
提出日時 | 2020-10-04 03:17:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 75 ms / 2,000 ms |
コード長 | 3,247 bytes |
コンパイル時間 | 2,018 ms |
コンパイル使用メモリ | 201,264 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 12:53:48 |
合計ジャッジ時間 | 3,630 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 5 ms
5,376 KB |
testcase_06 | AC | 5 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 31 ms
5,376 KB |
testcase_09 | AC | 36 ms
5,376 KB |
testcase_10 | AC | 14 ms
5,376 KB |
testcase_11 | AC | 25 ms
5,376 KB |
testcase_12 | AC | 13 ms
5,376 KB |
testcase_13 | AC | 41 ms
5,376 KB |
testcase_14 | AC | 62 ms
5,376 KB |
testcase_15 | AC | 54 ms
5,376 KB |
testcase_16 | AC | 69 ms
5,376 KB |
testcase_17 | AC | 46 ms
5,376 KB |
testcase_18 | AC | 34 ms
5,376 KB |
testcase_19 | AC | 21 ms
5,376 KB |
testcase_20 | AC | 73 ms
5,376 KB |
testcase_21 | AC | 20 ms
5,376 KB |
testcase_22 | AC | 75 ms
5,376 KB |
testcase_23 | AC | 3 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; /* * @title ModInt * @docs md/util/ModInt.md */ template<long long& mod> class ModInt { public: long long x; constexpr ModInt():x(0) {} constexpr ModInt(long long y) : x(y>=0?(y%mod): (mod - (-y)%mod)%mod) {} ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;} ModInt &operator+=(const long long y) {ModInt p(y);if((x += p.x) >= mod) x -= mod;return *this;} ModInt &operator+=(const int y) {ModInt p(y);if((x += p.x) >= mod) x -= mod;return *this;} ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;} ModInt &operator-=(const long long y) {ModInt p(y);if((x += mod - p.x) >= mod) x -= mod;return *this;} ModInt &operator-=(const int y) {ModInt p(y);if((x += mod - p.x) >= mod) x -= mod;return *this;} ModInt &operator*=(const ModInt &p) {x = (x * p.x % mod);return *this;} ModInt &operator*=(const long long y) {ModInt p(y);x = (x * p.x % mod);return *this;} ModInt &operator*=(const int y) {ModInt p(y);x = (x * p.x % mod);return *this;} ModInt &operator^=(const ModInt &p) {x = (x ^ p.x) % mod;return *this;} ModInt &operator^=(const long long y) {ModInt p(y);x = (x ^ p.x) % mod;return *this;} ModInt &operator^=(const int y) {ModInt p(y);x = (x ^ p.x) % mod;return *this;} ModInt &operator/=(const ModInt &p) {*this *= p.inv();return *this;} ModInt &operator/=(const long long y) {ModInt p(y);*this *= p.inv();return *this;} ModInt &operator/=(const int y) {ModInt p(y);*this *= p.inv();return *this;} ModInt operator=(const int y) {ModInt p(y);*this = p;return *this;} ModInt operator=(const long long y) {ModInt p(y);*this = p;return *this;} ModInt operator-() const {return ModInt(-x); } ModInt operator++() {x++;if(x>=mod) x-=mod;return *this;} ModInt operator--() {x--;if(x<0) x+=mod;return *this;} ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } ModInt operator^(const ModInt &p) const { return ModInt(*this) ^= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inv() const {int a=x,b=mod,u=1,v=0,t;while(b > 0) {t = a / b;swap(a -= t * b, b);swap(u -= t * v, v);} return ModInt(u);} ModInt pow(long long n) const {ModInt ret(1), mul(x);for(;n > 0;mul *= mul,n >>= 1) if(n & 1) ret *= mul;return ret;} friend ostream &operator<<(ostream &os, const ModInt &p) {return os << p.x;} friend istream &operator>>(istream &is, ModInt &a) {long long t;is >> t;a = ModInt<mod>(t);return (is);} }; long long mod; using modint = ModInt<mod>; int main() { long long A,B,C; cin >> A >> B >> C; mod = C; modint ans = 0; array<modint,100001> cnt; for(long long i = 1; i <= C; ++i) { cnt[i] = modint(i).pow(B); } for(long long i = 1; i <= A%C; ++i) { ans += cnt[i]; } ans += accumulate(cnt.begin(),cnt.begin()+C,modint(0))*(A/C); cout << ans << "\n"; return 0; }