Cod sursa(job #546427)

Utilizator alia_deiCristina Sirbu alia_dei Data 4 martie 2011 22:11:33
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<iostream.h>
#include<fstream.h>
int l=0;
ofstream g;

int dei(int s, int d, int a)
{
	int mij;
	if (d<s) return 0;
	else
	{
		mij=(s+d)/2;
		if (mij%5==0)
		{
			int aux=mij;
			while (aux%5==0)
			{
				l++;
				aux/=5;
			}
			if (l==a) g<<mij;
		//	else g<<"-1";
		}
		return dei(s,mij-1,a)+	dei(mij+1,d,a);
		
	}
	g.close();
}

int main()
{
	
	ifstream f;
	f.open("fact.in");
	int p;
	f>>p;
	g.open("fact.out");
	if (p==0) g<<"1";
	
	dei(1,p*5,p);
	if (l!=p) g<<"-1";
	f.close();
	g.close();
	
	return 0;
}