Cod sursa(job #2218326)
| Utilizator | Data | 4 iulie 2018 11:47:49 | |
|---|---|---|---|
| Problema | Factorial | Scor | 45 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long P;
long long st, dr, mid;
long long zero (long long x)
{
long long putere=5;
int cnt=0;
while(putere<=x) {
cnt+=x/putere;
putere*=5;
}
return cnt;
}
int main()
{
f>>P;
st=1;
dr=5*P;
mid=1;
while(st<=dr) {
mid=st+(dr-st)/2;
if(zero(mid)>=P)
dr=mid-1;
else st=mid+1;
}
g<<mid<<'\n';
return 0;
}
