Cod sursa(job #1808026)
| Utilizator | Data | 17 noiembrie 2016 10:53:50 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int test(int a)
{
int x=5;
int nr=0;
while(x<=a)
{
nr+=a/x;
x*=5;
}
return nr;
}
int p,n,st,dr,x,mid;
int main()
{
f>>p;
st=1;
dr=2000000000;
if(p==0) {g<<1;return 0;}
while(st<=dr)
{
mid=(st+dr)/2;
x=test(mid);
if(x==p)
break;
if(x<p)
{
st=mid+1;
}
else
{
dr=mid-1;
}
}
if(st<=dr)
{
while(test(mid)==p)
--mid;
mid++;
g<<mid;
}
else
g<<-1;
return 0;
}
