Cod sursa(job #2137962)
| Utilizator | Data | 21 februarie 2018 10:22:17 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p;
int fact(int n)
{
long long s=0;
while(n>=5)
s+=n/5, n/=5;
return s;
}
int cautbin(int n)
{
int st=0,m,dr=1000000000;
while(st<dr)
{
m=(st+dr)/2;
if(fact(m)>p) dr=m;
else st=m+1;
}
st-=5;
return st;
}
int main()
{
f>>p;
if(p==0)
g<<1;
else if(fact(cautbin(p))!=p)
g<<-1;
else g<<cautbin(p);
}
