Pagini recente » Cod sursa (job #627133) | Cod sursa (job #1614952) | Cod sursa (job #2456778) | Cod sursa (job #2729405) | Cod sursa (job #1461135)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
int64_t end_zero(int64_t p){
int64_t zeroes = 0;
while(p > 0){
zeroes += p / 5;
p /= 5;
}
return zeroes;
}
bool is_lower(int64_t 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, ok = 0;
int64_t a = 0 , b = 100000000000, c;
scanf("%d", &p);
if(p < 100)
b = 1000;
while(a < b){
c = (a+b) / 2;
if(end_zero(c) == p){
while(is_lower(c, p))
--c;
printf("%" PRId64, 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;
}