結果
| 問題 |
No.2365 Present of good number
|
| コンテスト | |
| ユーザー |
a01sa01to
|
| 提出日時 | 2023-06-30 22:45:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,197 bytes |
| コンパイル時間 | 2,141 ms |
| コンパイル使用メモリ | 208,988 KB |
| 最終ジャッジ日時 | 2025-02-15 04:19:52 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 WA * 22 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "settings/debug.cpp"
#define _GLIBCXX_DEBUG
#else
#define Debug(...) void(0)
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#include <atcoder/modint>
using mint = atcoder::modint1000000007;
void operator<<(ostream& os, const mint& m) { os << m.val(); }
int solve(int n, ll k) {
Debug(n, k);
vector<pair<ll, mint>> pf(0);
for (int i = 2; i * i <= n; ++i) {
if (n % i == 0) {
pf.push_back({ i, 0 });
while (n % i == 0) {
n /= i;
pf.back().second++;
}
}
}
if (n > 1) pf.push_back({ n, 1 });
Debug(pf);
while (k > 0) {
bool pfcond = false;
if (pf.size() > 2) pfcond = true;
for (auto [p, e] : pf)
if (p != 2 && p != 3) pfcond = true;
if (k % 2 == 1) pfcond = true;
if (!pfcond) break;
--k;
map<ll, mint> new_pf;
for (auto [p, e] : pf) {
ll new_p = p + 1;
for (int i = 2; i * i <= new_p; i++) {
while (new_p % i == 0) {
new_p /= i;
new_pf[i] += e;
}
}
if (new_p != 1) {
new_pf[new_p] += e;
}
}
pf.clear();
for (auto [p, e] : new_pf) {
pf.push_back({ p, e });
}
Debug(k, pf);
}
mint ans = 1;
if (k == 0) {
for (auto [p, e] : pf) {
ans *= mint(p).pow(e.val());
}
}
else {
assert(k % 2 == 0);
for (auto [p, e] : pf) {
if (p == 2) {
ans *= mint(2).pow((e * mint(2).pow(k / 2)).val());
}
else if (p == 3) {
ans *= mint(3).pow((e * mint(2).pow(k / 2)).val());
}
else {
assert(false);
}
}
}
return ans.val();
}
int main() {
ll n, k;
cin >> n >> k;
// cout << ans.val() << endl;
// for (int n = 2; n < 10000; n++) {
// for (int k = 1; k < 50000; k++) {
// int ans = solve(n, k);
// int ans_greedy = solve_greedy(n, k);
// if (ans_greedy == -1) {
// Debug(n, k, "OVERFLOW");
// break;
// }
// if (ans != ans_greedy) {
// Debug(n, k, ans, ans_greedy);
// return 0;
// }
// }
// }
cout << solve(n, k) << endl;
return 0;
}
a01sa01to