/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 792.0 KiB
#2 Accepted 2ms 788.0 KiB
#3 Accepted 4ms 788.0 KiB
#4 Accepted 4ms 788.0 KiB
#5 Accepted 32ms 840.0 KiB
#6 Accepted 31ms 844.0 KiB
#7 Accepted 3ms 788.0 KiB
#8 Accepted 4ms 844.0 KiB
#9 Accepted 152ms 872.0 KiB
#10 Accepted 357ms 924.0 KiB
#11 Accepted 70ms 788.0 KiB
#12 Accepted 11ms 788.0 KiB

Code

#include<bits/stdc++.h>
#define ll          long long
#define nl          '\n'
#define F           first
#define S           second
#define pb          push_back
#define all(a)      (a.begin()),(a.end())
#define Input       freopen("in.txt","r",stdin)
#define Output      freopen("out.txt","w",stdout)
#define PI          2*acos(0.0)
#define MOD         1000000007
using namespace std;


const int N = 2e5 + 5;

vector<ll>Prime;
bool mark[N];
void sieve(ll n) {
    ll i, j;
    mark[1] = 1;
    for (i = 4; i <= n; i += 2)
        mark[i] = 1;
    Prime.push_back(2);
    for (i = 3; i <= n; i += 2)
    {
        if (!mark[i])
        {
            Prime.push_back(i);
            if (i * i <= n)
            {
                for (j = i * i; j <= n; j += (i * 2))
                    mark[j] = 1;
            }
        }
    }
}
vector<ll> Factor;
// map<ll,ll> Factor;
void Primefactorize(ll n)
{
    Factor.clear();
    for (ll i = 0; i < Prime.size() && Prime[i]*Prime[i] <= n; i++)
    {
        if (n % Prime[i] == 0)
        {
            while (n % Prime[i] == 0)
            {
                Factor.push_back(Prime[i]);
                // Factor[Prime[i]]++;
                n /= Prime[i];
            }
        }
    }
    if (n > 1)
    {
        // Factor[n]++;
        Factor.push_back(n);
    }
}
void Solve()
{
    ll x, k;
    cin >> x >> k;
    Primefactorize(x);
    ll f = (k + 1) / 2;
    ll s = k / 2;
    ll n = Factor.size();
    n -= s;
    if (n < 1)
    {
        ll dis = 1 - n;
        n += dis;
        f -= dis;
    }

    ll ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= Factor[i];
    }
    while (f)
    {
        ans *= Factor[0];
        f--;
    }

    cout << ans << nl;

}

int main()
{
    sieve(100000);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, T = 1;
    cin >> T;
    for (t = 1; t <= T; t++)
        Solve();
    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 15:38:24
Judged At
2026-01-06 15:38:24
Judged By
Score
100
Total Time
357ms
Peak Memory
924.0 KiB