Cod sursa(job #492225)

Utilizator mihaif3feier mihai mihaif3 Data 13 octombrie 2010 20:38:12
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <stdio.h>
#include <string.h>
#include <math.h>

int p, t;
//--------------------------------
void read()
{
	freopen("fact.in", "rt", stdin);
	scanf("%d", &p);
}
//--------------------------------
int nbz(int n)
{
	int s;
	for(s=0; n > 1; n/=5)
		s += n/5;
	return s;
}
//--------------------------------
int search(int x, int y)
{
	if(x == y)
		return (nbz(x)==p? x: -1);
	int m = (x+y)/2;
	if(nbz((x+y)/2) < p)
		return search(m+1, y);
	return search(x, m);
}
//--------------------------------
void solve()
{
	if(p > 0)
		p = search(1, 1<<30);
	else p = 1;
}
//--------------------------------
void print()
{
	freopen("fact.out", "wt", stdout);
	printf("%d", p);
}
//--------------------------------
int main(void)
{
	read();
	solve();
	print();
	return 0;
}