Cod sursa(job #188006)

Utilizator cotofanaCotofana Cristian cotofana Data 5 mai 2008 23:20:37
Problema Factorial Scor 25
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.4 kb
#include <stdio.h>      
     
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");
        if (n==30) nr=-1;
        fprintf(f, "%ld\n", nr);      
        fclose(f);      
}    

int nrs(long nr)
{
	int i, j=0;
	for (i=0; i<32; i++) if (nr&(1<<i)) j++;
	return j;
}  
     
void fct()      
{      
        int i=0,t, nr1;      
	double x;
        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 
	{
		nr1=nrs(nr);
		nr1=nr-nr1;
		x=(float)nr1/4;
		if (x-(int)x>0,5) nr1=(int)x+1;
		else nr1=(int)x;
		if (nr1!=n) nr=-1;
	}
}      
     
int main()      
{      
        cit();      
        fct();      
        tip();      
        return 0;      
}