Cod sursa(job #2060373)
| Utilizator | Data | 8 noiembrie 2017 09:37:32 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.77 kb |
#include <iostream>
#include <fstream>
using namespace std;
unsigned long long f(unsigned long long x)
{
unsigned long long s=0;
while(x>0)
{
s+=x/5;
x/=5;
}
return s;
}
int main()
{
ifstream in("fact.in");
ofstream out ("fact.out");
unsigned long long p;
unsigned long long st=1,dr=1e18,m,x;
in>>p;
if(p==0)
{
out<<1;
return 0;
}
while(st<=dr){
m=(st+dr)/2;
x=f(m);
if(x==p)
{
if(f(m-1)!=p)
{
out<<m;
return 0;
}
dr=m;
}
if(x<p)
st=m+1;
else
dr=m-1;
}
out<<-1;
return 0;
}
