/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 72ms 20.211 MiB
#2 Wrong Answer 75ms 20.129 MiB
#3 Wrong Answer 77ms 20.445 MiB

Code

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<ll>v;
ll mxn=1e7+7;
bool mp[10000007];
void seive(){
  for(ll i=2;i<=mxn;i++){
    if(mp[i]==0){
      v.push_back(i);
      for(ll j=i+i;j<=mxn;j+=i){
        mp[j]=1;
      }
    }
  }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc=1,tc1=1;
    cin>>tc;
    seive();
    up:
    while(tc--){
      ll n,m,k,ans=2;
      cin>>n>>m>>k;
      for(ll i=max(2LL,n-m);i<=n+m;i++){
        if(i==n){
          continue;
        }
        if(mp[i]==0){
          ans=i;
        }
      }
      if(ans==2){
        for(ll i=max(2LL,n-m);i<=n+m;i++){
          if(i==n){
            continue;
          }
          for(ll j=2;j*j<=i;j++){
            if(i%j==0){
              ans=max(ans,j);
              break;
            }
          }
        }
      }
      k--;
      ll op,baki=1;
      for(ll cnt=1;cnt<=k;cnt++){
        ll lo=0,hi=v.size()-1,here=ans;
        while(lo<=hi){
          ll mid=(lo+hi)>>1LL;
          if(ans+m>=v[mid]){
            here=v[mid];
            lo=mid+1;
          }
          else {
            hi=mid-1;
          }
        }
        if(here==ans){
          baki=k-cnt;
          break;
        }
        else {
          ans=here;
        }
      }
      if(ans==2){
        for(ll i=2;i<=m+2;i++){
          if(mp[i]==0){
            op=i;
            break;
          }
        }
      }
      else {
        for(ll i=ans-1;i>=2;i--){
          if(mp[i]==0){
            op=i;
            break;
          }
        }
      }
      if(baki%2!=0){
        cout<<ans<<'\n';
      }
      else {
        cout<<op<<'\n';
      }
    }
}

Information

Submit By
Type
Submission
Problem
P1146 Yet Another Battle Between Roy and Hridoy!
Contest
LU IUJPC : Sylhet Division 2024 Replay Contest
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-10 13:01:48
Judged At
2024-12-10 13:01:48
Judged By
Score
1
Total Time
77ms
Peak Memory
20.445 MiB