Cod sursa(job #353735)

Utilizator andrei.sfrentSfrent Andrei andrei.sfrent Data 5 octombrie 2009 22:37:16
Problema Factorial Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<cstdio>

#define maxim(a, b) (a>b?a:b)

int p, x;

int zero(int n)
{
	int p5 = 5, r, suma = 0;
	while(1)
	{
		r = n / p5;
		if(r == 0) return suma;
		suma += r;
		p5 *= 5;
	}
}

void citeste()
{
	FILE* fi = fopen("fact.in", "r");
	fscanf(fi, "%d", &p);
	fclose(fi);
}

void scrie()
{
	FILE* fo = fopen("fact.out", "w");
	fprintf(fo, "%d\n", x);
	fclose(fo);
}

void rezolva()
{
	int li = 1; 
	int ls = 100000000;
	int mij;
	while(li < ls)
	{
		mij = (li + ls) / 2;
		if(zero(mij) < p)
			li = mij + 1;
		else
			ls = mij;
	}
	int ind = maxim(li, ls) + 4;
	while(zero(ind) >= p)
	{
		x = ind;
		ind--;
	}
}

int main()
{
	citeste();
	rezolva();
	scrie();
	return 0;
}