/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 424.0 KiB
#3 Runtime Error 1ms 564.0 KiB
#4 Runtime Error 1ms 532.0 KiB
#5 Runtime Error 1ms 532.0 KiB
#6 Runtime Error 5ms 440.0 KiB
#7 Runtime Error 2ms 532.0 KiB
#8 Runtime Error 4ms 3.02 MiB
#9 Runtime Error 5ms 3.246 MiB
#10 Runtime Error 1ms 532.0 KiB
#11 Runtime Error 1ms 560.0 KiB

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 = 1e6;

void solve()
{
   int n, k;
   cin >> n >> k;
   int ans = 0;
   if (n <= k)
   {
      ans = k - n;
   }
   int vis[n + 3] = {0};
   for (int i = 2; i <= k; i++)
   {
      if(i * n > k) break;
      if((k - (i * n)) * i < ans) break;
      
      if (vis[i] == 0)
      {

         for (int j = i; j <= k; j += i)
         {
            vis[j] = 1;
            int x = j * n;
            if (x <= k)
            {
               ans = max(ans, (j * (k - x)));
            }
            else
            {
               break;
            }
         }
      }
   }

   cout << ans << endll;
}

int32_t main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   int t = 1;
   cin >> t;
   while (t--)
   {
      solve();
   }
   return 0;
}

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-08 15:09:18
Judged At
2024-09-08 15:09:18
Judged By
Score
1
Total Time
5ms
Peak Memory
3.246 MiB