/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 439ms 161.688 MiB
#2 Accepted 450ms 161.676 MiB
#3 Accepted 466ms 161.695 MiB
#4 Accepted 585ms 161.555 MiB
#5 Accepted 570ms 161.621 MiB
#6 Accepted 472ms 161.688 MiB
#7 Wrong Answer 450ms 161.695 MiB
#8 Accepted 485ms 161.668 MiB
#9 Accepted 480ms 161.621 MiB
#10 Accepted 471ms 161.621 MiB
#11 Wrong Answer 460ms 161.867 MiB

Code

#include <bits/stdc++.h>
#define int long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int mod = 1e9 + 7, N = 1e7 + 9999 + 9;

vector<int> prime, spf(N), primeVis(N);
void sp()
{
    for (int i = 1; i < N; i++)
        spf[i] = i;
    for (int p = 2; p < N; p++)
    {
        if (spf[p] == p)
        {
            prime.pb(p);
            primeVis[p] = 1;
            for (int i = p * 2; i < N; i += p)
                spf[i] = min(p, spf[i]);
        }
    }
}

int k, n, m;

void solve()
{
    map<int, int> mp;

    int prev = -1;
    // memset(dp, 0, sizeof dp);
    // memset(vis, 0, sizeof dp);
    // cout << endll;
    cin >> n >> m >> k;
    // k *= 2;
    // cout << rec(nn, 1) << endll;
    int mx = -1;
    int rem = -1;
    int ok = 0;
    for (int i = 1; i <= k; i++)
    {
        int prm = -1, non_prm = -1, node = -1;
        vector<int> v;
        for (int j = 1; j <= m; j++)
        {
            if (spf[n + j] == n + j)
            {
                prm = max(prm, n + j);
                v.pb(n + j);
            }
            else
            {

                prm = max(prm, spf[n + j]);
                v.pb(spf[n + j]);
            }

            if (n - j >= 2)
            {
                if (spf[n - j] == n - j)
                {
                    prm = max(prm, n - j);
                    v.pb(n - j);
                }
                else
                {

                    prm = max(prm, spf[n - j]);
                    v.pb(spf[n - j]);
                }
            }
        }
        n = prm;
        sort(all(v));
        for (auto j : v)
        {
            // cout << j<< " = " << prm << endll;
            if (j != prm)
            {
                if (j + m >= prm)
                {
                    ok = 1;
                }
            }
        }
        // cout << n << endll;
        mx = max(mx, n);
        // cout << i << " = " << n << endll;
        if (mp[n])
        {

            // cout << "PAichi at = " << mp[n] << endll; ;
            // cout << n << " " << k - i << endll;
            rem = k - i;
            break;
            // ;
        }
        prev = n;
        mp[n] = i;
    }

    if (ok)
    {
        cout << mx << endll;
    }
    else
    {
        cout << n << endll;
    }

    // if (rem != -1)
    // {
    // }
    // else
    //     cout << n << endll;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sp();
    // for (int i = 1; i <= 100; i++)
    // {
    //     cout << spf[i] << " ";
    // }
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1146 Yet Another Battle Between Roy and Hridoy!
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-26 10:27:04
Judged At
2024-12-26 10:27:04
Judged By
Score
25
Total Time
585ms
Peak Memory
161.867 MiB