/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.52 MiB
#2 Accepted 3ms 1.496 MiB
#3 Accepted 5ms 1.52 MiB
#4 Accepted 8ms 1.523 MiB
#5 Accepted 32ms 1.527 MiB
#6 Accepted 33ms 1.52 MiB
#7 Accepted 5ms 1.523 MiB
#8 Accepted 6ms 1.531 MiB
#9 Accepted 152ms 1.758 MiB
#10 Accepted 354ms 1.598 MiB
#11 Accepted 75ms 1.551 MiB
#12 Accepted 14ms 1.539 MiB

Code

#include <bits/stdc++.h>     //   All praise is due to Allah alone, and peace and blessings be
using namespace std;         //         upon him, after whom there is no other Prophet.

vector<int64_t> spf, pr;
void SPF(const int64_t len) {
    spf.resize(len + 1);
    iota(spf.begin(), spf.end(), 0);
    for (int64_t i = 2; i * i <= len; i++) {
        if (spf[i] == i) {
            for (int64_t j = i * i; j <= len; j += i) {
                if (spf[j] == j) spf[j] = i;
            }
        }
    }
}
void prime(const int64_t len) {
    SPF(len);
    pr.push_back(2);
    for (int64_t i = 3; i <= len; i += 2) {
        if (spf[i] == i) pr.push_back(i);
    }
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    prime(1e5);

    int32_t Case = 1;    cin >> Case;
    for (int T = 1; T <= Case; T++) {

        int64_t n, k; cin >> n >> k;
        vector<int64_t> val;
        for(const int64_t i : pr) {
            if(i * i > n) break;
            while(n % i == 0) {
                val.push_back(i);
                n /= i;
            }
        }
        if(n > 1) val.push_back(n);
        sort(val.begin(), val.end());


        int ok = val.size();

        int cnt = min<int64_t>(20, k);
        for(int i = 1; i <= cnt; i++) {
            if(i & 1) {
                val.push_back(val.front());
            }
            else {
                val.pop_back();
            }
            sort(val.begin(), val.end());
        }
        if(k > 20 and k & 1) {
            val.push_back(val.front());
        }
        int64_t ans = 1;
        
        for(const int64_t i : val) {
            ans *= i;
        }
        cout << ans << '\n';
    }
    return 0;
}

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 16:09:19
Judged At
2026-01-06 16:09:19
Judged By
Score
100
Total Time
354ms
Peak Memory
1.758 MiB