Skip to content

Instantly share code, notes, and snippets.

@utahta
Created January 12, 2021 08:52
Show Gist options
  • Save utahta/7e57a59e5906a5404e8d2dadf1b5d728 to your computer and use it in GitHub Desktop.
Save utahta/7e57a59e5906a5404e8d2dadf1b5d728 to your computer and use it in GitHub Desktop.
階乗の桁数と末尾0の個数
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
int main() {
ll n;
cin >> n;
ll tmp = n;
ll zero = 0;
while (tmp >= 5) {
zero += tmp / 5;
tmp /= 5;
}
double keta = n * (log10((double)n)-0.43429448190325) + 0.5*log10(M_PI*2.0*n);
cout << int(keta)+1 << " " << zero << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment