Cod sursa(job #219982)

Utilizator Bogdan_tmmTirca Bogdan Bogdan_tmm Data 9 noiembrie 2008 00:41:29
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.69 kb
#include<iostream>
#include<stdio.h>
FILE *f,*g;
long p,n=0,x5=0,x2=0,aux,i,j,t,q,t2=1;
long putere(long x,long y)
{
	long i;long rez=1;
	for(i=1;i<=y;i++)
		rez*=x;
	return rez;
}	
void rezolv()
{
       int t1=1;x5=x2=0;i=0;t=0;
		while(t1)
		{
			i++;
			aux=n/putere(5,i);
			if(!aux) t1=0;
			x5+=aux;
			aux=n/putere(2,i);
			if(!aux) t1=0;
			x2+=aux;
		}
		x2=x2>x5?x5:x2;
		if(x2==p) t=1;
}
void div(long i,long j)
{
	n=i;
	rezolv();
	if(t) q=n;
	else
		if(x2<p)
			 div(n+1,j);
		else
			 div(i+1,n);
}
int main()
{
	f=fopen("fact.in","r");
	g=fopen("fact.out","w");
	fscanf(f,"%ld",&p);
	div(1,100000000);
	fprintf(g,"%ld",q);
	return 0;
}