Pagini recente » Rating Muresan Natalia (____natalia) | Cod sursa (job #2967539) | Cod sursa (job #1207248) | Cod sursa (job #2760384) | Cod sursa (job #1413316)
#include <iostream>
#include <stdio.h>
using namespace std;
int p;
const int MAXQ=100000000;
int aparitii (int n)
{
int ap=0, putere=5;
while(n>=putere) { ap=ap+n/putere; putere*=5; }
return ap;
}
int main(int argc, char *argv[])
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d", &p);
if(p==0) { printf("%d \n", 1); return 0; }
else
{
int l=2, q=MAXQ;
while(l<=q)
{
int m=l+(q-l)/2;
int ap=aparitii(m);
if(ap==p) { printf("%d \n", m/5*5); return 0; }
else
if(ap>p) q=m-1;
else l=m+1;
}
printf("%d \n", -1);
return 0;
}
}