BOJ : https://www.acmicpc.net/problem/3474
github : https://github.com/junho0956/Algorithm/blob/master/3474/3474/%EC%86%8C%EC%8A%A4.cpp
0이라는 수를 만들기 위해서는 2와 5가 필요합니다.
2배수, 5배수씩 소인수분해 해주시면서 곱해지는 2,5 의 갯수를 구해주시면 그중 최솟값이 0의 갯수가 됩니다.
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
int f = 0, t = 0, num;
cin >> num;
for (int i = 2; i <= num; i *= 2)
t += num / i;
for (int i = 5; i <= num; i *= 5)
f += num / i;
int ans = f > t ? t : f;
cout << ans << '\n';
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
|
'algorithm > BOJ' 카테고리의 다른 글
| BOJ 12813번 이진수 연산 (0) | 2020.02.02 |
|---|---|
| BOJ 2143번 두 배열의 합 (0) | 2020.02.02 |
| BOJ 2632번 피자판매 (0) | 2020.02.02 |
| BOJ 7453번 합이 0인 네 정수 (0) | 2020.02.01 |
| BOJ 1208번 부분수열의 합 2 (0) | 2020.02.01 |