Cod sursa(job #1366495)
| Utilizator | Data | 1 martie 2015 09:59:38 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int main ()
{
int p,c,gasit;
long long s,d,m,x;
s=1;
d=1000000000;
fin>>p ;
gasit=0;
while(s<=d && gasit==0)
{
m=(s+d)/2;
x=m;
c=0;
while(x!=0)
{
c=c+x/5 ;
x=x/5;
}
if(c==p)
{
if(p==0) fout<<"1";
else fout<<m-m%5;
gasit=1;
}
else if (c>p) d=m-1;
else s=m+1;
}
if(gasit==0) fout<<"-1";
fin.close();
fout.close();
return 0;
}
