Pagini recente » Cod sursa (job #2927997) | Cod sursa (job #1554688) | Cod sursa (job #117165) | Cod sursa (job #311724) | Cod sursa (job #1856079)
#include <cstdio>
FILE *in,*out;
using namespace std;
const int L = 30;
int nrcifrezero(int x)
{
int r = 0;
while(x != 0) {
r += x/5;
x /= 5;
}
return r;
}
int cauta(int x)
{
int pas,r = 0;
pas = 1 << L;
while(pas != 0) {
if(nrcifrezero(r + pas) < x)
r += pas;
pas /= 2;
}
r ++;
if(nrcifrezero(r) != x)
return -1;
return r;
}
int main()
{
in = fopen("fact.in","r");
out = fopen("fact.out","w");
int p;
fscanf(in,"%d",&p);
if(p == 0)
fprintf(out,"1");
else
fprintf(out,"%d",cauta(p));
return 0;
}