Cod sursa(job #187995)

Utilizator cotofanaCotofana Cristian cotofana Data 5 mai 2008 22:45:28
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.46 kb

#include <stdio.h>      
#include <time.h>

clock_t start, end;     
long n;      
long nr;      
     
void cit()      
{      
        FILE *f=fopen("fact.in", "r");      
        fscanf(f, "%ld", &n);      
        fclose(f);      
}      
     
void tip()      
{      
        FILE *f=fopen("fact.out", "w");      
        fprintf(f, "%ld\n", nr);      
        fclose(f);      
}    

int put5(int nr)
{
	int i=0;
	while (nr%5==0) {i++;nr/=5;}
	return i;
}  
     
void fct()      
{      
        int i=0,t, nr2;      
        while (nr<n)      
        {      
                i+=5;      
                nr+=5;      
                if (nr<n)      
                {      
                t=i;      
                do     
                {      
     
                        if (t%5==0) t/=5;      
                        nr++;      
                } while (t%5==0);      
                }      
                else     
                {      
                        i-=nr-n;      
                }      
        }      
        nr=5*i;   
        if (n==0) nr=1;   
	else
	{
		nr2=0;
		end=clock();
		for (i=5; i<=nr; i+=5)
		{
			if ((float)end-start<49/100*CLK_TCK) break;
			nr2+=put5(i);
			end=clock();
		}
		if (i>nr) if (nr2!=n) nr=-1;
	}
}      
     
int main()      
{    
	start=clock();  
        cit();      
        fct();      
        tip();      
        return 0;      
}