/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 5ms 532.0 KiB
#4 Accepted 327ms 576.0 KiB
#5 Wrong Answer 200ms 584.0 KiB
#6 Time Exceeded ≥1596ms ≥568.0 KiB

Code

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define nl              cout<<'\n';
#define space           cout<<' ';
#define pb              push_back
#define fs              first
#define sc              second
#define pii             pair<int,int>


#define ll              long long
#define all(x)          (x).begin(), (x).end()
#define Point(x,y)      setprecision((y))<<fixed<<(x)

#define yes             cout<<"YES\n"
#define no              cout<<"NO\n"

#define Fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(x)          cout<<"line " << __LINE__ << " says: " << #x << " = " << x << "\n";

#define printarry(a)    for(auto it : a) cout<<it<<' ';
#define put_array(x,n)  for (int i = 0; i < n; ++i) cin >> x[i];
#define vec(a, n)         vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];


template<typename T >    void cn(T &t) { cin >> t; }
template<typename T ,    typename... Args> void cn(T &t, Args&... args) { cin >> t; cn(args...);}
template<typename T >    void pr(const T &t) { cout << t; }
template<typename T ,    typename... Args>void pr(const T &t, const Args&... args) {cout << t << ' '; pr(args...); }
template<typename T>     using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>     using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;







//-----------------------------------------------------------------------------------------------------------------------------------
//                                                  PRACTICE AND LEARN
//-----------------------------------------------------------------------------------------------------------------------------------

#define int long long

void test_case()
{
    int n, k;
    cin >> n >> k;

    map<int, int>mp;
    for (int i = 2; i * i <= n ; ++i)
    {
        while (n % i == 0)
        {
            n = n / i;
            mp[i]++;
        }
    }

    if (n > 1)
    {
        mp[n]++;
    }



    for (int i = 1; i <= min(k , 100000ll)  ; ++i)
    {
        if (i % 2 == 1) //odd
        {
            int mn = mp.begin()->first;
            mp[mn]++;
        }
        else
        {
            int mx = mp.rbegin()->first;
            mp[mx]--;
            if (mp[mx] == 0)
            {
                mp.erase(mx);
            }
        }

    }

    int num =1;
    for(auto it : mp)
    {
        int key = it.fs;
        int val = it.sc;
        num *= pow(key , val);
    }

    cout << num;





    nl
    return;

}




int32_t main()
{
    Fast;

#ifdef NAYEEM

    int start_time = clock();
    int end_time = clock();
    printf("Time = %.4f\n", (end_time - start_time + 0.0) / CLOCKS_PER_SEC);

#endif

    int test_number = 1;
    cin >> test_number;

    for (int i = 1; i <= test_number; ++i)
    {
        // cout << "Case "<< i <<": " << "\n" ;
        test_case();
    }

    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:25:32
Judged At
2026-01-06 16:25:32
Judged By
Score
15
Total Time
≥1596ms
Peak Memory
≥584.0 KiB