結果
| 問題 |
No.2365 Present of good number
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2023-06-30 23:07:40 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#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';
}
hitonanode