結果
問題 | No.2365 Present of good number |
ユーザー | hitonanode |
提出日時 | 2023-06-30 23:07:40 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 5,411 bytes |
コンパイル時間 | 906 ms |
コンパイル使用メモリ | 104,452 KB |
実行使用メモリ | 7,900 KB |
最終ジャッジ日時 | 2024-07-07 11:03:12 |
合計ジャッジ時間 | 2,092 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
7,756 KB |
testcase_01 | AC | 7 ms
7,700 KB |
testcase_02 | AC | 7 ms
7,804 KB |
testcase_03 | AC | 8 ms
7,756 KB |
testcase_04 | AC | 8 ms
7,772 KB |
testcase_05 | AC | 8 ms
7,884 KB |
testcase_06 | AC | 8 ms
7,756 KB |
testcase_07 | AC | 8 ms
7,756 KB |
testcase_08 | AC | 8 ms
7,764 KB |
testcase_09 | AC | 7 ms
7,844 KB |
testcase_10 | AC | 8 ms
7,876 KB |
testcase_11 | AC | 8 ms
7,852 KB |
testcase_12 | AC | 8 ms
7,852 KB |
testcase_13 | AC | 8 ms
7,828 KB |
testcase_14 | AC | 8 ms
7,752 KB |
testcase_15 | AC | 8 ms
7,660 KB |
testcase_16 | AC | 8 ms
7,784 KB |
testcase_17 | AC | 8 ms
7,696 KB |
testcase_18 | AC | 8 ms
7,756 KB |
testcase_19 | AC | 8 ms
7,900 KB |
testcase_20 | AC | 8 ms
7,696 KB |
testcase_21 | AC | 7 ms
7,824 KB |
testcase_22 | AC | 8 ms
7,756 KB |
testcase_23 | AC | 8 ms
7,856 KB |
testcase_24 | AC | 7 ms
7,868 KB |
testcase_25 | AC | 8 ms
7,696 KB |
testcase_26 | AC | 7 ms
7,768 KB |
testcase_27 | AC | 8 ms
7,760 KB |
testcase_28 | AC | 8 ms
7,780 KB |
testcase_29 | AC | 8 ms
7,756 KB |
testcase_30 | AC | 7 ms
7,760 KB |
testcase_31 | AC | 8 ms
7,816 KB |
testcase_32 | AC | 8 ms
7,752 KB |
testcase_33 | AC | 7 ms
7,808 KB |
testcase_34 | AC | 7 ms
7,764 KB |
testcase_35 | AC | 7 ms
7,724 KB |
testcase_36 | AC | 8 ms
7,828 KB |
testcase_37 | AC | 8 ms
7,784 KB |
testcase_38 | AC | 7 ms
7,852 KB |
testcase_39 | AC | 7 ms
7,848 KB |
testcase_40 | AC | 7 ms
7,820 KB |
ソースコード
#include <cassert> #include <iostream> #include <map> #include <utility> #include <vector> using namespace std; using lint = long long; template <int md> struct ModInt { #if __cplusplus >= 201402L #define MDCONST constexpr #else #define MDCONST #endif using lint = long long; MDCONST static int mod() { return md; } int val_; int val() const noexcept { return val_; } MDCONST ModInt() : val_(0) {} MDCONST ModInt &_setval(lint v) { return val_ = (v >= md ? v - md : v), *this; } MDCONST ModInt(lint v) { _setval(v % md + md); } MDCONST explicit operator bool() const { return val_ != 0; } MDCONST ModInt operator+(const ModInt &x) const { return ModInt()._setval((lint)val_ + x.val_); } MDCONST ModInt operator-(const ModInt &x) const { return ModInt()._setval((lint)val_ - x.val_ + md); } MDCONST ModInt operator*(const ModInt &x) const { return ModInt()._setval((lint)val_ * x.val_ % md); } MDCONST ModInt operator/(const ModInt &x) const { return ModInt()._setval((lint)val_ * x.inv().val() % md); } MDCONST ModInt operator-() const { return ModInt()._setval(md - val_); } MDCONST ModInt &operator+=(const ModInt &x) { return *this = *this + x; } MDCONST ModInt &operator-=(const ModInt &x) { return *this = *this - x; } MDCONST ModInt &operator*=(const ModInt &x) { return *this = *this * x; } MDCONST ModInt &operator/=(const ModInt &x) { return *this = *this / x; } friend MDCONST ModInt operator+(lint a, const ModInt &x) { return ModInt()._setval(a % md + x.val_); } friend MDCONST ModInt operator-(lint a, const ModInt &x) { return ModInt()._setval(a % md - x.val_ + md); } friend MDCONST ModInt operator*(lint a, const ModInt &x) { return ModInt()._setval(a % md * x.val_ % md); } friend MDCONST ModInt operator/(lint a, const ModInt &x) { return ModInt()._setval(a % md * x.inv().val() % md); } MDCONST bool operator==(const ModInt &x) const { return val_ == x.val_; } MDCONST bool operator!=(const ModInt &x) const { return val_ != x.val_; } MDCONST bool operator<(const ModInt &x) const { return val_ < x.val_; } // To use std::map<ModInt, T> friend std::istream &operator>>(std::istream &is, ModInt &x) { lint t; return is >> t, x = ModInt(t), is; } MDCONST friend std::ostream &operator<<(std::ostream &os, const ModInt &x) { return os << x.val_; } MDCONST ModInt pow(lint n) const { ModInt ans = 1, tmp = *this; while (n) { if (n & 1) ans *= tmp; tmp *= tmp, n >>= 1; } return ans; } static std::vector<ModInt> facs, facinvs, invs; MDCONST static void _precalculation(int N) { int l0 = facs.size(); if (N > md) N = md; if (N <= l0) return; facs.resize(N), facinvs.resize(N), invs.resize(N); for (int i = l0; i < N; i++) facs[i] = facs[i - 1] * i; facinvs[N - 1] = facs.back().pow(md - 2); for (int i = N - 2; i >= l0; i--) facinvs[i] = facinvs[i + 1] * (i + 1); for (int i = N - 1; i >= l0; i--) invs[i] = facinvs[i] * facs[i - 1]; } MDCONST ModInt inv() const { if (this->val_ < std::min(md >> 1, 1 << 21)) { if (facs.empty()) facs = {1}, facinvs = {1}, invs = {0}; while (this->val_ >= int(facs.size())) _precalculation(facs.size() * 2); return invs[this->val_]; } else { return this->pow(md - 2); } } MDCONST ModInt fac() const { while (this->val_ >= int(facs.size())) _precalculation(facs.size() * 2); return facs[this->val_]; } MDCONST ModInt facinv() const { while (this->val_ >= int(facs.size())) _precalculation(facs.size() * 2); return facinvs[this->val_]; } }; template <int md> std::vector<ModInt<md>> ModInt<md>::facs = {1}; template <int md> std::vector<ModInt<md>> ModInt<md>::facinvs = {1}; template <int md> std::vector<ModInt<md>> ModInt<md>::invs = {0}; using mint = ModInt<1000000007>; using mint2 = ModInt<1000000006>; struct Sieve { std::vector<int> min_factor; std::vector<int> primes; Sieve(int MAXN) : min_factor(MAXN + 1) { for (int d = 2; d <= MAXN; d++) { if (!min_factor[d]) { min_factor[d] = d; primes.emplace_back(d); } for (const auto &p : primes) { if (p > min_factor[d] or d * p > MAXN) break; min_factor[d * p] = p; } } } }; Sieve sieve((1 << 20)); int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N; lint K; cin >> N >> K; map<int, mint2> mp; while (N > 1) mp[sieve.min_factor.at(N)] += 1, N /= sieve.min_factor.at(N); while (K) { if (mp.size() <= 2 and prev(mp.end())->first <= 3 and K % 2 == 0) break; --K; const map<int, mint2> mpold = mp; mp.clear(); for (auto [p, d] : mpold) { int q = p + 1; while (q > 1) { mp[sieve.min_factor.at(q)] += d; q /= sieve.min_factor.at(q); } } } const auto c = mint2(2).pow(K / 2); mint ret = 1; for (auto [p, d] : mp) ret *= mint(p).pow((d * c).val()); cout << ret << '\n'; }