Advertisement
Imran1107048

C. K-th Not Divisible by n

Jul 1st, 2021
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define int long long
  6. #define endl "\n"
  7. #define PI acos(-1.0)
  8. #define IN freopen("input.txt",'r',stdin)
  9.  
  10. const int MOD = 1e9+7;
  11. const int INF = 2e5+5;
  12. const int N = 205;
  13.  
  14. void solve();
  15. int32_t main()
  16. {
  17. IOS;
  18. cout << fixed << setprecision(10);
  19. int _ = 1;
  20. cin >> _;
  21. while(_--) solve();
  22. return 0;
  23. }
  24.  
  25. void solve()
  26. {
  27. int n, k;
  28. cin >> n >> k;
  29. int l = 1, h = INT_MAX;
  30. int cnt = 0;
  31.  
  32. while(l<=h){
  33. int mid = (l+h)/2;
  34. int temp = mid - mid / n;
  35.  
  36. if(temp == k){
  37. cnt = mid;
  38. h = mid-1;
  39. }
  40. else if(temp > k){
  41. h = mid - 1;
  42. }
  43. else{
  44. l = mid + 1;
  45. }
  46. }
  47. cout << cnt << endl;
  48. }
  49.  
  50. ///Must see the constraints range
  51. ///Calculate the Time
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement