Cod sursa(job #593434)

Utilizator qwertyuPeter Eke qwertyu Data 2 iunie 2011 19:01:09
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#define _CRT_SECURE_NO_DEPRECATE

#include <stdio.h>
#include <stdlib.h>


int zero(int x)
{
	int i=0,j=5,q=1;
	
	while (q != 0)
	{
		q = x / j;
		i += q;
		j*=5;
	}

	return i;
}

int main()
{
	FILE * f = fopen("fact.in","r");
	int p,n;
	fscanf(f,"%d",&p);
    fclose(f);




	n=5*p;
	while (zero(n)>p) n-=5;
	while (zero(n)<p) n+=5;

	if (n == 0) n++;

	f = fopen("fact.out","w");
	fprintf(f,"%d",n);
	fclose(f);
	
	return 0;
}