644 div3 problem D (buying shovel) codeforces


why m i getiing Wrong answer?

You are simply writing lengthy code . Don’t reduce n for each factor of i, you can sqrt(n), also check for i along with n/i<=k. Check this implementation ,this passed the testcases.

       int t; cin >> t;       
while (t--) {
              int n, k; cin >> n >> k; 
             int ans = INT_MAX; 
             for (int i = 1; i <= sqrt(n); i++) {
                     if (n % i == 0) {  
                          if (i <= k)      ans = min(ans, n / i);
                            if ((n / i) <= k)  ans = min(ans, i);
                     }
              } 
             cout << ans << endl; 
       }

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.