/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 564.0 KiB
#2 Time Exceeded ≥1593ms ≥764.0 KiB
#3 Time Exceeded ≥1590ms ≥532.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define nl "\n"
bool isPrime(int n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n % 2 == 0) return false;
    for (int i = 3; i * i <= n; i += 2){ 
        if (n % i == 0) return false; } 
    return true; 
}

ll small(ll n) {
    for (ll i = 2; i <= n; i++) {
        if(isPrime(i) && n % i == 0) return i;
    }
}

ll large(ll n) {
    for (ll i = n; i >= 2; i--) {
        if(isPrime(i) && n % i == 0) return i;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t;
    cin>>t;
    while(t--){
        ll x, k; cin>>x>>k;
        char ch = 'r';
        while (k--) {
            if (ch == 'r') {
                int p = small(x);
                x *= p;
                ch = 'h';
            }
            else {
                int p = large(x);
                x /= p;
                ch = 'r';
            }

        }

        cout<<x<<nl;
    }

    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:12:20
Judged At
2026-01-06 15:12:20
Judged By
Score
0
Total Time
≥1593ms
Peak Memory
≥764.0 KiB