/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 15ms 576.0 KiB
#4 Accepted 15ms 324.0 KiB
#5 Accepted 211ms 588.0 KiB
#6 Accepted 193ms 576.0 KiB
#7 Accepted 4ms 532.0 KiB
#8 Accepted 11ms 764.0 KiB
#9 Accepted 1182ms 620.0 KiB
#10 Time Exceeded ≥1598ms ≥640.0 KiB
#11 Accepted 489ms 596.0 KiB
#12 Accepted 32ms 584.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;

vector<pair<ll, ll>> factorize(ll n) {
    vector<pair<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.emplace_back(i, cnt);
        }
    }
    if (n > 1) res.emplace_back(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.pop_back();
        }
    }

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

    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:17:27
Judged At
2026-01-06 15:17:28
Judged By
Score
95
Total Time
≥1598ms
Peak Memory
≥764.0 KiB