結果
問題 | No.2365 Present of good number |
ユーザー | AnchorBlues |
提出日時 | 2023-09-23 13:56:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,845 bytes |
コンパイル時間 | 2,923 ms |
コンパイル使用メモリ | 228,540 KB |
実行使用メモリ | 7,348 KB |
最終ジャッジ日時 | 2024-07-16 13:35:35 |
合計ジャッジ時間 | 5,194 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 19 ms
7,208 KB |
testcase_01 | AC | 18 ms
7,216 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 19 ms
7,220 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 18 ms
7,232 KB |
testcase_17 | AC | 18 ms
7,292 KB |
testcase_18 | AC | 18 ms
7,240 KB |
testcase_19 | AC | 18 ms
7,348 KB |
testcase_20 | AC | 18 ms
7,228 KB |
testcase_21 | AC | 19 ms
7,276 KB |
testcase_22 | AC | 19 ms
7,208 KB |
testcase_23 | AC | 19 ms
7,284 KB |
testcase_24 | AC | 19 ms
7,224 KB |
testcase_25 | AC | 19 ms
7,220 KB |
testcase_26 | AC | 18 ms
7,244 KB |
testcase_27 | AC | 19 ms
7,236 KB |
testcase_28 | AC | 19 ms
7,248 KB |
testcase_29 | AC | 19 ms
7,244 KB |
testcase_30 | AC | 18 ms
7,228 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 18 ms
7,204 KB |
testcase_37 | AC | 19 ms
7,180 KB |
testcase_38 | AC | 18 ms
7,268 KB |
testcase_39 | AC | 18 ms
7,208 KB |
testcase_40 | AC | 18 ms
7,208 KB |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:297:31: warning: 'three_e' may be used uninitialized [-Wmaybe-uninitialized] 297 | pf = {{2, three_e * (1LL << (L + 1))}, {3, two_e * (1LL << L)}}; | ~~~~~~~~^~~~~~~~~~~~~~~~~~ main.cpp:288:23: note: 'three_e' was declared here 288 | ll two_e, three_e; | ^~~~~~~ main.cpp:297:62: warning: 'two_e' may be used uninitialized [-Wmaybe-uninitialized] 297 | pf = {{2, three_e * (1LL << (L + 1))}, {3, two_e * (1LL << L)}}; | ~~~~~~^~~~~~~~~~~~ main.cpp:288:16: note: 'two_e' was declared here 288 | ll two_e, three_e; | ^~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; const ll INF = 1LL << 60; const ll Z = 1000000000 + 7; template <class T> void chmax(T& a, T b) { if (b > a) a = b; } template <class T> void chmin(T& a, T b) { if (b < a) a = b; } template <typename T, typename S> std::ostream& operator<<(std::ostream& os, const pair<T, S>& x) noexcept { return os << "(" << x.first << ", " << x.second << ")"; } template <typename T> void print_vector(vector<T> a) { cout << '['; for (int i = 0; i < a.size(); i++) { cout << a[i]; if (i != a.size() - 1) { cout << ", "; } } cout << ']' << endl; } template <ll MOD> class ModInt { public: constexpr ModInt() { val = 0; } constexpr ModInt(ll v) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getval() const noexcept { return val; } constexpr ModInt operator-() const noexcept { if (val == 0) return 0; return MOD - val; } constexpr ModInt operator+(const ModInt& r) const noexcept { return ModInt(*this) += r; } constexpr ModInt operator-(const ModInt& r) const noexcept { return ModInt(*this) -= r; } constexpr ModInt operator*(const ModInt& r) const noexcept { return ModInt(*this) *= r; } constexpr ModInt operator/(const ModInt& r) const noexcept { return ModInt(*this) /= r; } constexpr ModInt& operator+=(const ModInt& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr ModInt& operator-=(const ModInt& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr ModInt& operator*=(const ModInt& r) noexcept { val = val * r.val % MOD; return *this; } constexpr ModInt& operator/=(const ModInt& r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const ModInt& r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const ModInt& r) const noexcept { return this->val != r.val; } friend constexpr std::ostream& operator<<(std::ostream& os, const ModInt<MOD>& x) noexcept { return os << x.val; } // n乗 を MOD で割った余り constexpr ModInt<MOD> pow(ll n) noexcept { if (n == 0) return 1; auto t = this->pow(n / 2); t = t * t; if (n & 1) t = t * val; return t; } // 逆元 constexpr ModInt<MOD> inv() noexcept { ModInt<MOD> one = 1; return one / *this; } ModInt<MOD>& operator=(ll v) noexcept { val = v % MOD; return *this; } ModInt<MOD>& operator=(const ModInt<MOD>& v) noexcept { val = v.val % MOD; return *this; } private: ll val; }; using mint = ModInt<Z>; ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll ceilll(ll x, ll y) { return (x + y - 1) / y; } ll mod(ll x, ll y) { return (x + 10000000) % y; } // 約数全列挙 vector<ll> all_divisors(ll K) { vector<ll> ret; for (ll i = 1; i * i <= K; i++) { if (K % i != 0) continue; ret.push_back(i); if (i * i != K) ret.push_back(K / i); } return ret; } // 素因数分解 vector<pair<ll, ll>> prime_factorize(ll N) { vector<pair<ll, ll>> res; for (ll a = 2; a * a <= N; ++a) { if (N % a != 0) continue; ll ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } class Eratosthenes { public: // コンストラクタ Eratosthenes(); Eratosthenes(int); // 高速素因数分解 vector<pii> factorize(int n) const; // 素数判定 bool is_prime(int n) const; // 約数の個数 int n_divisors(int n) const; private: std::vector<bool> _isprime; std::vector<int> _minfactor; }; // コンストラクタ Eratosthenes::Eratosthenes() {} Eratosthenes::Eratosthenes(int N) { _isprime = std::vector<bool>(N + 1, true); _minfactor = std::vector<int>(N + 1, -1); // 1 は予めふるい落としておく _isprime[1] = false; _minfactor[1] = 1; // 篩 for (int p = 2; p <= N; ++p) { // すでに合成数であるものはスキップする if (!_isprime[p]) continue; // p についての情報更新 _minfactor[p] = p; // p 以外の p の倍数から素数ラベルを剥奪 for (int q = p * 2; q <= N; q += p) { // q は合成数なのでふるい落とす _isprime[q] = false; // q は p で割り切れる旨を更新 if (_minfactor[q] == -1) _minfactor[q] = p; } } } vector<pii> Eratosthenes::factorize(int n) const { vector<pii> res; while (n > 1) { int p = _minfactor[n]; int exp = 0; // n で割り切れる限り割る while (_minfactor[n] == p) { n /= p; ++exp; } res.emplace_back(p, exp); } return res; } bool Eratosthenes::is_prime(int n) const { return _isprime[n]; } int Eratosthenes::n_divisors(int n) const { auto tmp = this->factorize(n); int ret = 1; for (auto& v : tmp) { ret *= v.second + 1; } return ret; } auto es = Eratosthenes(1000000); vector<pll> f(vector<pll>& pf) { unordered_map<ll, ll> mp; for (auto& v : pf) { ll q = v.first + 1; auto x = es.factorize(q); for (auto& u : x) { mp[u.first] += v.second * u.second; } } vector<pll> ret; for (auto& v : mp) { ret.push_back({v.first, v.second}); } return ret; } // 2^a * 4^b の形になっているか bool is_2a3b(vector<pll>& pf) { if (pf.size() > 2) return false; for (auto& v : pf) { if (v.first != 2 && v.first != 3) return false; } return true; } void solve() { ll N, K; cin >> N >> K; auto pf = prime_factorize(N); // // 愚直な実装 開始 // for (int i = 0; i < K; i++) { // pf = f(pf); // } // // 愚直な実装 終了 // print_vector(pf); while (true) { if (K == 0) break; if (is_2a3b(pf)) break; pf = f(pf); // print_vector(pf); K--; } if (K > 0) { if (K % 2 == 0) { vector<pll> npf; for (auto& v : pf) { npf.push_back({v.first, v.second * (1LL << K / 2)}); } pf = npf; } else { ll L = (K - 1) / 2; ll two_e, three_e; for (auto& v : pf) { if (v.first == 2) { two_e = v.second; } if (v.first == 3) { three_e = v.second; } } pf = {{2, three_e * (1LL << (L + 1))}, {3, two_e * (1LL << L)}}; } } mint ret = 1; for (auto& v : pf) { ret *= mint(v.first).pow(v.second); } std::cout << ret << "\n"; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; while (T--) { solve(); } return 0; }