Cod sursa(job #730561)
Utilizator | Data | 6 aprilie 2012 15:18:56 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.37 kb |
#include<fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int n,st,dr,m;
int f(int a)
{
int x=0,c=5;
while(a>=c){
x+=a/c;
c*=5;
}
return x;
}
int main()
{
in>>n;
st=1;dr=5*n;
while(st<=dr){
m=((st+dr)>>1);
if(f(m)<n)
st=m+1;
else
dr=m-1;
}
if(f(st)==n)
out<<st;
else
out<<"-1";
return 0;
}