/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1ms 540.0 KiB
#2 Time Exceeded ≥1093ms ≥540.0 KiB

Code

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

#define ll long long
#define endl '\n'
#define pi 2*acos(0.0)

const int N = 1e6;
int a[N];

void solve() 
{   
    ll n, m, k; cin >> n >> m >> k;
    ll x = n;
    ll last_n1 = 3168, last_n2 = -234;
    for (int _ = 1; _ <= k; _++) {
        ll y = -1;

        for (ll i = max(2LL, n - m); i <= n + m; i++) {
            if (i == n) {
                continue;
            }
            //cout << i << endl;
            ll ans = i;
            for (ll j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    ans = j;
                    break;
                }
            } 
            if (ans >= y) {
                y = ans;
            }
        }

        //cout << y << endl;
        if (_ % 2 == 0) {
            last_n2 = n;
        }
        else {
            last_n1 = n;
        }
        n = y;
        if (_ % 2 == 0 && last_n2 == n) {
            if (k % 2 == 0) {
                cout << last_n2 << endl; return;
            }
            else {
                cout << last_n1 << endl; return;
            }
        }
        else if (_ % 2 == 1 && last_n1 == n) {
            if (k % 2 == 1) {
                cout << last_n1 << endl; return;
            }
            else {
                cout << last_n2 << endl; return;
            }
        }
    }
    cout << n << endl;

}

int main () 
{

    ios::sync_with_stdio(false); cin.tie(nullptr);
    

    ll t = 1; 
    //cin >> t;
    while(t--) {
        solve();
    }

    return 0;


}

Information

Submit By
Type
Submission
Problem
P1146 Yet Another Battle Between Roy and Hridoy!
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 07:12:33
Judged At
2024-12-09 07:12:33
Judged By
Score
0
Total Time
≥1093ms
Peak Memory
≥540.0 KiB