/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 4ms 788.0 KiB
#4 Accepted 4ms 788.0 KiB
#5 Accepted 29ms 788.0 KiB
#6 Accepted 29ms 788.0 KiB
#7 Accepted 4ms 788.0 KiB
#8 Accepted 5ms 788.0 KiB
#9 Accepted 155ms 832.0 KiB
#10 Accepted 324ms 916.0 KiB
#11 Accepted 65ms 816.0 KiB
#12 Accepted 11ms 824.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long int 
vector<bool> isPrime;
vector<int> primes;
void init_sieve(int n,bool genArr){
    isPrime.resize(n, true);
    isPrime[0] = false;
    isPrime[1] = false;
    for (int i = 2;  i*i < n; i++){
        if (isPrime[i]){
            for (int j = i*i; j < n; j+=i) isPrime[j] = false;
        }
    }
    if (genArr){
      for (int i=2; i<n;i++) {
        if (isPrime[i]) primes.push_back(i);
      }
    }
}

long long binexp(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1) res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    #ifdef SUBLIME
        freopen("inputf.in", "r", stdin);
        freopen("outputf.out", "w", stdout);
        freopen("error.txt", "w", stderr);
    #endif

    init_sieve(1e5, true);

    int tt;
    cin >> tt;

    while (tt--) {
        int n, k;
        cin >> n >> k;

        vector <pair <int, int>> vp;
        for (auto p : primes) {
            if (p * 1LL * p > n) break;
            if (n % p == 0) {
                int cnt = 0;
                while (n % p == 0) {
                    n /= p;
                    cnt++;
                }
                vp.push_back({p, cnt});
            }
        }
        if (n > 1) vp.push_back({n, 1});

        int dcnt = k / 2, mcnt = k - dcnt;

        vp.front().second += mcnt;
        for (int i = vp.size() - 1; i >= 0; i--) {
            int x = min(dcnt, vp[i].second);
            vp[i].second -= x;
            dcnt -= x;
            if (dcnt == 0) break;
        }

        int ans = 1;
        for (auto [v, f] : vp) ans *= binexp(v, f);
        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:38:54
Judged At
2026-01-06 16:38:54
Judged By
Score
100
Total Time
324ms
Peak Memory
916.0 KiB