Mai intai trebuie sa te autentifici.
Cod sursa(job #1225353)
| Utilizator | Data | 2 septembrie 2014 14:15:29 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long p;
int nrzero(long x)
{
long nr5=5,nr=0;
while(nr5<=x)
{
nr+=x/nr5;
nr5*=5;
}
return nr;
}
int cautbin(long st,long dr)
{long x;
if(st==dr)
{if(nrzero(st)==p) {return st;}}
else{
int m=(st+dr)>>1;
if(nrzero(m)>=p)
{x=cautbin(st,m);}
else
{x=cautbin(m+1,dr);}
return x;}
}
int main()
{
f>>p;f.close();
if(p==0) {g<<1;return 0;}
long nr=cautbin(p,5*p);
if(nrzero(nr)==p) g<<nr;
else g<<-1;
g.close();
return 0;
}
