/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Runtime Error 8ms 780.0 KiB
#3 Runtime Error 8ms 540.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define yes cout<<"YES"<<"\n";
#define no cout<<"NO"<<"\n";
#define forn  for(int i=0;i<n;i++);
#define acin  for(int i=0;i<n;i++)cin>>arr[i];
#define v vector<int>arr(n);
#define int long long
const int mx=123;
bool isprime[mx];
vector<int>prime;
void solve()
{
  int n, m, k;
  cin >> n >> m >> k; // k-x,x1,x2;
 if(m==1){cout<<n<<endl;return;}

  int p = 1;
  while (k--)
  {
      //if(p>m)break;
    if (n - p >= 2)
      n -= p;
    else
    {
      n += p;
      if (n % 2 == 0)
      {
        int c = n / 2;
        n = n / c;
      }
      else
      {

        if (isprime[n])
          n = n;
        else
        {
          int c = n / 2;
          for (int i = c; i >= 1; i--)
          {
            if (n % i == 0)
            {
              n /= i;
            }
          }
        }
      }
    }
    p++;
  }
 cout<<n<<endl;
}

int32_t main()
{
  for (int i = 3; i <= mx; i += 2)
    isprime[i] = 1;
  for (int i = 3; i <= sqrt(mx); i++)
  {
    if (isprime[i])
    {
      for (int j = i * i; j <= mx; j += i)
      {
        isprime[j] = 0;
      }
    }
  }
  isprime[2] = 1;
  prime.push_back(2);
  for (int i = 3; i <= mx; i += 2)
  {
    if (isprime[i] == 1)
      prime.push_back(i);
  }
  int t;
  cin >> t;
  while (t--)
  {
    solve();
  }
}

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:39:14
Judged At
2024-12-09 07:39:14
Judged By
Score
1
Total Time
8ms
Peak Memory
780.0 KiB