Pagini recente » Cod sursa (job #2414761) | Cod sursa (job #668061) | Cod sursa (job #1172089) | Cod sursa (job #1143454) | Cod sursa (job #1461132)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int end_zero(int p){
int zeroes = 0;
while(p > 0){
zeroes += p / 5;
p /= 5;
}
return zeroes;
}
bool is_lower(int n, int p){
--n;
if(end_zero(n) == p)
return true;
else
return false;
}
int main()
{
freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
int p, a = 0 , b = 1000000, c, ok = 0;
scanf("%d", &p);
while(a < b){
c = (a+b) / 2;
if(end_zero(c) == p){
while(is_lower(c, p))
--c;
printf("%d", c);
ok = 1;
break;
}
else {
if(end_zero(c) < p)
a = c + 1;
else
if (end_zero(c) > p)
b = c - 1;
}
}
if(!ok)
printf("-1");
return 0;
}