Cod sursa(job #2451722)
| Utilizator | Data | 27 august 2019 23:15:32 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long int factorial(unsigned long p) {
unsigned long nrz = 0;
while (p >= 5) {
nrz += p / 5;
p /= 5;
}
return nrz;
}
int main() {
unsigned long p;
cin >> p;
unsigned long long int b = 10000000000; //
int a = 0;
int mid; // maybe wrtong;
while (b >= a) {
mid = (a + b) / 2;
if (p > factorial(mid)) {
a = mid + 1;
}
else {
b = mid - 1;
}
}
cout << mid;
return 0;
}
