Cod sursa(job #219940)

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