Cod sursa(job #550843)

Utilizator RampageSergiu Caraian Rampage Data 9 martie 2011 22:52:14
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <fstream>
using namespace std;

ifstream f ("fact.in");
ofstream g ("fact.out");

int main ()
	{
	long p,s=0,a=1,b=2000000,x,i,j;
	bool flag=false;
	f>>p;

	if (p==0)
		g<<1;
	else
		{
		while (flag==false && a<=b)
			{
			s=0;
			x=(a+b)/2;
			for (i=0; i<=x; i+=5)
				{
				j=i;
				while (j%5==0 && j>0)
					{
					j/=5;
					s++;
					}
				}
			
			if (s==p)
				flag=true;
			if (s>p)
				b=x-1;
			if (s<p)
				a=x+1;
			}
		if (a>b)
			g<<-1;
		if (s==p)
			{
			while (x%5!=0)
				x-=1;
			g<<x;
			}
		}
	
	g.close();
	return 0;
	}