fork download
  1. #include <iostream>
  2. using namespace std;
  3. bool isPrime(long int n)
  4. {
  5. if (n <= 1) return false;
  6. if (n <= 3) return true;
  7. if (n%2 == 0 || n%3 == 0) return false;
  8.  
  9. for (int i=5; i*i<=n; i=i+6)
  10. if (n%i == 0 || n%(i+2) == 0)
  11. return false;
  12.  
  13. return true;
  14. }
  15. int main() {
  16. // your code goes here
  17. int t;
  18. cin>>t;
  19. while(t--)
  20. {
  21. long int n,k;
  22. cin>>n>>k;
  23. int i =1;
  24. if(k>=n)
  25. {
  26. cout<<"1"<<"\n";
  27. }
  28. else if(isPrime(n) || k==1)
  29. {
  30. cout<<n<<"\n";
  31. }
  32. else
  33. {
  34. i=n/k;
  35. while(k<(n/i))
  36. {
  37. i++;
  38. while(n%i!=0)
  39. {
  40. i++;
  41. }
  42. }
  43.  
  44. cout<<i<<"\n";
  45. }
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 4544KB
stdin
5
45 7
8 1
6 10
999999733 999999732
999999733 999999733
stdout
6
8
1
999999733
1