Dang_Quan_10_Tin

NFACTOR (ChatGPT)

Mar 21st, 2023
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5.  
  6. ll count_trailing_zeros(ll n) {
  7.     ll count = 0;
  8.     for (ll i = 5; n / i >= 1; i *= 5) {
  9.         count += n / i;
  10.     }
  11.     return count;
  12. }
  13.  
  14. ll binary_search(ll n) {
  15.     ll left = 0;
  16.     ll right = 5 * n;
  17.  
  18.     while (left < right) {
  19.         ll mid = (left + right) / 2;
  20.         ll num_zeros = count_trailing_zeros(mid);
  21.         if (num_zeros >= n) {
  22.             right = mid;
  23.         } else {
  24.             left = mid + 1;
  25.         }
  26.     }
  27.     return left;
  28. }
  29.  
  30. int main() {
  31.     ios_base::sync_with_stdio(0);
  32.     cin.tie(0);
  33.     int t;
  34.     cin >> t;
  35.     while (t--) {
  36.         ll n;
  37.         cin >> n;
  38.         cout << binary_search(n) << endl;
  39.     }
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment