Mai intai trebuie sa te autentifici.
Cod sursa(job #1391873)
| Utilizator | Data | 18 martie 2015 11:11:08 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n, p, u, m, x, i, s;
int calculeaza(int x){
s=0;
for(i=5; i<=x; i*=5)
s+=x/i;
return s;
}
int main(){
f>>n;
if(n==0)
{
g<<"1\n";
return 0;
}
p=1;
u=5*n;
while(p<=u)
{
m=(p+u)>>1;
x=calculeaza(m);
if(x==n)
{
m=m-(m%5);
g<<m<<"\n";
return 0;
}
if(x<n)
p=m+1;
else
u=m-1;
}
g<<"-1\n";
return 0;
}
