BAEKJOON/C++

[B1676][팩토리얼 0의 개수][C++]

sseni 2021. 6. 23. 19:21
728x90

https://www.acmicpc.net/problem/1676


#include <iostream>
using namespace std;

int n;
int cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> n;
	while (n >= 5) {
		cnt += n / 5;
		n /= 5;
	}
	cout << cnt;
}

다른 사람 알고리즘 찾아보기 ..

요즘 풀고 나서 찾았던 알고리즘 중 제일 충격 

세상 제일 짧다 ..

#include <iostream>
using namespace std;

int n;

int main() {
	cin >> n;
	cout << n/5 + n/25 + n/125;
}

근데 시간은 똑같네

 

728x90