Pagini recente » Cod sursa (job #3162159) | Cod sursa (job #24324) | Cod sursa (job #2948285) | Cod sursa (job #502675) | Cod sursa (job #1196698)
#include <stdio.h>
using namespace std;
int p;
int cp(int p)
{
int aux=1,i;
for (i=1; i<=p; i++) aux*=5;
return aux;
}
int zerouri(int nr){
int c=0,i,aux;
i=1;
while (i)
{
aux=nr/cp(i);
if (aux==0) i=-1;
else c+=aux;
i++;
}
return c;
}
int main(){
int z=0, a,b,aux; bool gasit=false;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d", &p);
a=0;
b=100000000;
while ((a<=b) && (!gasit))
{
aux=(a+b) /2;
z = zerouri(aux);
if (z>p) {b=aux-1;}
else if (z<p) {a=aux+1;}
else gasit=true;
}
while(zerouri(aux-1)==p) aux--;
if (p==0) printf("1");
else if (gasit) printf("%d",aux);
else printf("-1");
return 0;
}