Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll count_trailing_zeros(ll n) {
- ll count = 0;
- for (ll i = 5; n / i >= 1; i *= 5) {
- count += n / i;
- }
- return count;
- }
- ll binary_search(ll n) {
- ll left = 0;
- ll right = 5 * n;
- while (left < right) {
- ll mid = (left + right) / 2;
- ll num_zeros = count_trailing_zeros(mid);
- if (num_zeros >= n) {
- right = mid;
- } else {
- left = mid + 1;
- }
- }
- return left;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- ll n;
- cin >> n;
- cout << binary_search(n) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment