Pagini recente » Monitorul de evaluare | Istoria paginii utilizator/stay_awake77 | Statistici Macovei Cristian (cristi_macovei) | Profil Le_Account | Cod sursa (job #561314)
Cod sursa(job #561314)
#include <stdio.h>
#define INFILE "fact.in"
#define OUTFILE "fact.out"
int P;
int fact(int N)
{
int p = 5;
int count = 0;
while (p<=N) {
count += N/p;
p = p*5;
}
return count;
}
int cauta(int target, int low, int high)
{
int mid, count;
while (low < high) {
mid = (low + high)/2;
count = fact(mid);
if (target == count)
return mid;
if (target < count)
high = mid-1;
else
low = mid+1;
}
return -1;
}
int main()
{
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
scanf("%d", &P);
if (P == 0) {
printf("1");
return 0;
}
int low = 0;
int high = 400020000;
int result = cauta(P, low, high);
if (result == -1) {
printf("-1");
return 0;
}
result = result/5*5;
printf("%d\n", result);
return 0;
}