Pagini recente » Cod sursa (job #2972932) | Cod sursa (job #415695) | Cod sursa (job #767927) | Cod sursa (job #1897638) | Cod sursa (job #2453188)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
unsigned int save_tens(unsigned long *p)
{
unsigned int nr = 0;
while (*p % 10 == 0)
{
*p = *p / 10;
nr++;
}
return nr;
}
unsigned long ipow(unsigned long base, unsigned long exp)
{
int result = 1;
while (1)
{
if (exp & 1)
result *= base;
exp >>= 1;
if (!exp)
break;
base *= base;
}
return result;
}
unsigned int len(unsigned int n)
{
unsigned int count = 0;
while (n)
{
n = n / 10;
count++;
}
return count;
}
int main()
{
FILE* f = fopen("fact.in", "rt");
unsigned long n, p=1, i=2, count=0;
fscanf(f, "%lu", &n);
while (count != n)
{
p = (p * i) % 1000;
count = count + save_tens(&p);
i++;
}
f = fopen("fact.out", "wt");
fprintf(f, "%lu \n", i-1);
fflush(stdout);
fclose(f);
return 0;
}