結果
| 問題 |
No.2365 Present of good number
|
| コンテスト | |
| ユーザー |
hitonanode
|
| 提出日時 | 2023-06-30 23:08:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,481 bytes |
| コンパイル時間 | 983 ms |
| コンパイル使用メモリ | 106,796 KB |
| 実行使用メモリ | 7,856 KB |
| 最終ジャッジ日時 | 2024-07-07 11:03:59 |
| 合計ジャッジ時間 | 2,194 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <cassert>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;
#include <atcoder/modint>
using mint = atcoder::modint1000000007;
using mint2 = atcoder::static_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;
long long 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.val() << '\n';
}
hitonanode