結果
問題 | No.984 Inversion |
ユーザー | FF256grhy |
提出日時 | 2020-02-11 15:33:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 4,764 bytes |
コンパイル時間 | 1,529 ms |
コンパイル使用メモリ | 178,196 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-01 07:58:36 |
合計ジャッジ時間 | 2,243 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 1 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 1 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,820 KB |
testcase_11 | AC | 1 ms
6,820 KB |
testcase_12 | AC | 1 ms
6,816 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 1 ms
6,820 KB |
testcase_15 | AC | 1 ms
6,816 KB |
testcase_16 | AC | 2 ms
6,816 KB |
testcase_17 | AC | 1 ms
6,816 KB |
testcase_18 | AC | 2 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,824 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 1 ms
6,820 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 2 ms
6,816 KB |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,820 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using LL = long long int; #define incID(i, l, r) for(int i = (l) ; i < (r); ++i) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i) #define incII(i, l, r) for(int i = (l) ; i <= (r); ++i) #define decII(i, l, r) for(int i = (r) ; i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define dec(i, n) decID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define FR front() #define BA back() #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() auto setmin = [](auto & a, auto b) { return (b < a ? a = b, true : false); }; auto setmax = [](auto & a, auto b) { return (b > a ? a = b, true : false); }; auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); }; auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); }; #define SI(v) static_cast<int>(v.size()) #define RF(e, v) for(auto & e: v) #define until(e) while(! (e)) #define if_not(e) if(! (e)) #define ef else if #define UR assert(false) #define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__); void IN_() { }; template<typename T, typename ... U> void IN_(T & a, U & ... b) { cin >> a; IN_(b ...); }; template<typename T> void OUT(T && a) { cout << a << endl; } template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); } // ---- ---- template<int N = 0> class DynModInt { private: static LL M; LL v; pair<LL, LL> ext_gcd(LL a, LL b) { if(b == 0) { assert(a == 1); return { 1, 0 }; } auto p = ext_gcd(b, a % b); return { p.SE, p.FI - (a / b) * p.SE }; } public: DynModInt() { v = 0; } DynModInt(LL vv) { assert(M > 0); v = vv; if(abs(v) >= M) { v %= M; } if(v < 0) { v += M; } } static void set_M(LL m) { M = m; } static LL get_M() { return M; } LL get_v() { return v; } DynModInt inv() { return ext_gcd(M, v).SE; } DynModInt exp(LL b) { DynModInt p = 1, a = v; if(b < 0) { a = a.inv(); b = -b; } while(b) { if(b & 1) { p *= a; } a *= a; b >>= 1; } return p; } friend bool operator< (DynModInt a, DynModInt b) { return (a.v < b.v); } friend bool operator> (DynModInt a, DynModInt b) { return (a.v > b.v); } friend bool operator<=(DynModInt a, DynModInt b) { return (a.v <= b.v); } friend bool operator>=(DynModInt a, DynModInt b) { return (a.v >= b.v); } friend bool operator==(DynModInt a, DynModInt b) { return (a.v == b.v); } friend bool operator!=(DynModInt a, DynModInt b) { return (a.v != b.v); } friend DynModInt operator+ (DynModInt a ) { return DynModInt(+a.v); } friend DynModInt operator- (DynModInt a ) { return DynModInt(-a.v); } friend DynModInt operator+ (DynModInt a, DynModInt b) { return DynModInt(a.v + b.v); } friend DynModInt operator- (DynModInt a, DynModInt b) { return DynModInt(a.v - b.v); } friend DynModInt operator* (DynModInt a, DynModInt b) { return DynModInt(a.v * b.v); } friend DynModInt operator/ (DynModInt a, DynModInt b) { return a * b.inv(); } friend DynModInt operator^ (DynModInt a, LL b) { return a.exp(b); } friend DynModInt & operator+=(DynModInt & a, DynModInt b) { return (a = a + b); } friend DynModInt & operator-=(DynModInt & a, DynModInt b) { return (a = a - b); } friend DynModInt & operator*=(DynModInt & a, DynModInt b) { return (a = a * b); } friend DynModInt & operator/=(DynModInt & a, DynModInt b) { return (a = a / b); } friend DynModInt & operator^=(DynModInt & a, LL b) { return (a = a ^ b); } friend istream & operator>>(istream & s, DynModInt & b) { s >> b.v; b = DynModInt(b.v); return s; } friend ostream & operator<<(ostream & s, DynModInt b) { return (s << b.v); } }; template<int N> LL DynModInt<N>::M = 0; // ---- using DMI = DynModInt<>; vector<pair<LL, LL>> prime_factorization(LL x) { assert(x > 0); vector<pair<LL, LL>> f; for(LL i = 2; i <= x; i++) { if(i * i > x) { i = x; } if(x % i == 0) { f.EB(i, 0); while(x % i == 0) { f.back().SE++; x /= i; } } } return f; } vector<LL> divisors(LL x) { auto pf = prime_factorization(x); vector<LL> d = { 1 }; for(auto e: pf) { int ds = d.size(); inc(i, ds) { LL v = d[i]; inc(j, e.SE) { v *= e.FI; d.PB(v); } } } sort(ALL(d)); return d; } int main() { IN(LL, p, n); DMI::set_M(p); auto D = divisors(p - 1); LL ans = -1; RF(d, D) { if((DMI(n) ^ d) == DMI(1)) { ans = ((d - 1) * (p - 1) / d) % 2; break; } } assert(ans != -1); OUT(ans); }