/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 764.0 KiB
#3 Accepted 5ms 532.0 KiB
#4 Accepted 7ms 764.0 KiB
#5 Accepted 207ms 584.0 KiB
#6 Accepted 227ms 580.0 KiB
#7 Accepted 4ms 536.0 KiB
#8 Accepted 7ms 576.0 KiB
#9 Accepted 1244ms 612.0 KiB
#10 Time Exceeded ≥1597ms ≥636.0 KiB
#11 Accepted 511ms 608.0 KiB
#12 Accepted 32ms 604.0 KiB

Code

#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>

using ll = long long;

using namespace std;

ll n, k;

map<ll, ll> factorize(ll n) {
    map<ll, ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            ll cnt = 0;
            while (n % i == 0) {
                cnt++;
                n /= i;
            }
            res[i] = cnt;
        }
    }
    if (n > 1) res[n] = 1;
    return res;
}

void solve() {
    cin >> n >> k;
    auto factors = factorize(n);

    ll i = 0;
    while (i < k && factors.size() > 1) {
        i++;
        if (i % 2) {
            factors.begin()->second++;
        } else {
            auto it = prev(factors.end());
            it->second--;
            if (it->second == 0) factors.erase(it);
        }
    }

    if ((k - i) % 2) {
        i++;
        if (i % 2) {
            factors.begin()->second++;
        } else {
            auto it = prev(factors.end());
            it->second--;
            if (it->second == 0) factors.erase(it);
        }
    }

    ll res = 1;
    for (auto &[x, y]: factors) {
        for (int i = 0; i < y; ++i) res *= x;
    }
    cout << res << "\n";
}

int main() {
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
}

Information

Submit By
Type
Submission
Problem
P1194 D. Roy and Prime Game
Contest
Happy New Year 2026
Language
C++17 (G++ 13.2.0)
Submit At
2026-01-06 15:13:40
Judged At
2026-01-06 15:13:41
Judged By
Score
95
Total Time
≥1597ms
Peak Memory
≥764.0 KiB