Cod sursa(job #397384)

Utilizator gandruAlexandru Gheorghiu - UPB gandru Data 16 februarie 2010 21:04:51
Problema Factorial Scor 15
Compilator c Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <stdio.h>
#include <math.h>

long putere(long t)
{
	if (t%5>0) return 1;
	else return (1+putere(t/5));
}

int main()
{
	long p,t=0,s=0,k=0,x,max=0;
	FILE *f,*g;
		
	f=fopen("fact.in","r");
	fscanf(f,"%li",&p);
	fclose(f);
	g=fopen("fact.out","w");
	
	if (p==0) { fprintf(g,"%i ",1); }
	else
		{
			while (s<p)
				{
					t++;
					x=putere(t);
					s=s+x;
					if (max<x) { max=x; k=0; }
					k=k+pow(5,x);
				}
			if (s>p) fprintf(g,"%i ",-1);
			else fprintf(g,"%li ",k);
		}
	fclose(g);
	return 0;
}