https://www.acmicpc.net/problem/11687
#include <bits/stdc++.h>
using namespace std;
int countZero(int n)
{
int cnt = 0;
while (n >= 5)
{
cnt += n / 5;
n /= 5;
}
return cnt;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int m;
cin >> m;
int bottom = 0, top = m * 5, ans = -1;
while (bottom <= top)
{
int mid = (bottom + top) / 2;
int tmp = countZero(mid);
if (tmp < m)
{
bottom = mid + 1;
}
else
{
if (tmp == m)
ans = mid;
top = mid - 1;
}
}
cout << ans;
return 0;
}
728x90
'백준이당' 카테고리의 다른 글
[C++] 백준 2512번 : 예산 (0) | 2025.05.14 |
---|---|
[C++] 백준 7562번 : 나이트의 이동 (0) | 2025.04.16 |
[C++] 백준 1325번 : 효율적인 해킹 (0) | 2025.04.16 |
[C++] 백준 24480번 : 알고리즘수업 - 깊이 우선 탐색2 (0) | 2025.04.16 |
[C++] 백준 : 2667번 : 단지번호붙이기 (0) | 2025.04.05 |