Cod sursa(job #614342)
| Utilizator | Data | 6 octombrie 2011 09:33:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.58 kb |
#include <fstream>
using namespace std;
#define ll long long
ll zero(ll c)
{ll p;
for(p=0;c;p+=c/5 ,c/=5);
return p;
}
ll p , a , b , c , fn , i ;
bool ok;
int main()
{
ifstream fin("fact.in");
ofstream fout("fact.out");
fin>>p;
a=1, b=5 * p , c=a + (b-a)/2 , c=c-c%5;
while(a<=c && c<=b && a<=b && !ok)
{
fn = zero(c);
if(fn==p) ok = true , i = c;
else
if(fn<p)
a = c + 1;
else
b=c-1;
c=a + (b-a)/2;
c-=c%5;
}
if(!p) fout<<1;
else
if(!ok) fout<<-1;
else
fout<<i;
return 0;
}
