/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 16ms 532.0 KiB
#4 Accepted 19ms 532.0 KiB
#5 Accepted 1245ms 604.0 KiB
#6 Accepted 1254ms 604.0 KiB
#7 Accepted 6ms 584.0 KiB
#8 Accepted 20ms 580.0 KiB
#9 Accepted 1184ms 628.0 KiB
#10 Time Exceeded ≥1593ms ≥636.0 KiB
#11 Time Exceeded ≥1596ms ≥596.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define eb emplace_back
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define here cout<<"HERE !!!"<<endl;
#define sz(v) (ll)v.size()
#define vi vector<ll>
#define print(v) for (auto it : v) cout << it << " "; cout << endl;
#define all(v) v.begin(), v.end()
#define i128 __int128
#define read(v) for(auto &it:v) cin>>it;
#define Faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace  __gnu_pbds;

#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
const long double pi = acos(-1.0l);
const ll inf = 4e18;
const int mod = 998244353, mx = 1e5 + 100;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll my_rand(ll l, ll r)
{
    return uniform_int_distribution<ll>(l, r)(rng);
}
//rotate(v.begin(), v.begin() + d, v.end());
//order_of_key(k): number of element less than k
//find_by_order(k): k-th element in set start from 0

void ravana(ll idx)
{
    ll n, k;   cin >> n >> k;
    bool f = true;
    vi v;
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            v.pb(i);
            v.pb(n / i);
            f = false;
        }
    }
    if (f)
    {
        k %= 2;
        if (k == 1)
        {
            cout << n*n << endl;
        }
        else
        {
            cout << n << endl;
        }
        return;
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    //print(v);
    vi temp;
    for (auto it : v)
    {
        bool f = true;
        if (it % 2 == 0 and it > 2)
            continue;
        for (ll i = 3; i * i <= it; i += 2)
        {
            if (it % i == 0)
            {
                f = false;
                break;
            }
        }
        if (f)
            temp.pb(it);
    }
    v = temp;
    //print(v);

    ll x = 1;
    while (sz(v) > 1)
    {
        if (x)
        {
            n *= v[0];
        }
        else
        {
            if (n % v.back() == 0)
            {
                n /= v.back();
            }
            else
            {
                v.popb();
                n /= v.back();
            }
        }
        k--;
        x ^= 1;
        if (k == 0)
        {
            cout << n << endl;
            return;
        }
    }
    k %= 2;
    if (k == 1)
    {
        cout << n*v[0] << endl;
    }
    else
    {
        cout << n << endl;
    }
}

signed main()
{
    auto begin = std::chrono::high_resolution_clock::now();
    Faster;
    ll t = 1;
    cin >> t;
    for (ll i = 1; i <= t; ++i)
    {
        ravana(i);
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\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:42:39
Judged At
2026-01-06 16:42:39
Judged By
Score
85
Total Time
≥1596ms
Peak Memory
≥636.0 KiB