Cod sursa(job #2001297)
| Utilizator | Data | 16 iulie 2017 13:10:31 | |
|---|---|---|---|
| Problema | Factorial | Scor | 35 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.52 kb |
#include<cstdio>
using namespace std;
int mult5(int x)
{
int nr=0;
while(x%5==0)
{
nr++;
x=x/5;
}
return nr;
}
int fact(int x)
{
int s=0,p=5;
if(x==0)
return 1;
while(x>mult5(p)+s)
{
s=s+mult5(p);
p=p+5;
}
if(x==mult5(p)+s)
return p;
return -1;
}
int main()
{
int n;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&n);
printf("%d",fact(n));
return 0;
}
