Pagini recente » Rezultatele filtrării | Cod sursa (job #2261693)
#include <stdio.h>
int pow(int base, int exp)
{
if (exp == 0) return 1;
int res = 1;
if (exp % 2 == 1)
res *= base;
int pr = pow(base, exp/2);
res*=pr*pr;
return res;
}
int getZeros(int p)
{
int calc = 5;
int zeros = 0;
while (calc <= p)
{
zeros += p/calc;
calc *= 5;
}
return zeros;
}
int main()
{
// freopen("fact.in", "rt", stdin);
// freopen("fact.out", "wt", stdout);
int p;
scanf("%i", &p); //19 breaks
int bot = 0, top = 100000000000;//pow(5, p);
while (bot != top)
{
int midpoint = (bot+top)/2;
if (getZeros(midpoint)>=p)
top = midpoint;
else
bot = midpoint+1;
}
printf("%i! is the smallest with at least %i trailing zeroes\n", bot?bot:1, p);
}
//40005! is 166737 digits long with 9999 trailing zeros