Cod sursa(job #988588)

Utilizator petrutsxMihaela Petruta Gaman petrutsx Data 23 august 2013 12:57:45
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<stdio.h>
int P, N, k, q = 1;

int power(int x){
	if(x >= N)
		return 0;
	else{
		q = q * 5;
		return 1 + power(x * 5);
	}
}

int count(int q){
	if(q * 4 <= N)
		return 4;
	else
		if(q * 3 <= N)
			return 3;
		else
			if(q * 2 <= N)
				return 2;
}

int main(){
	FILE *pf, *pg;
	
	pf = fopen("fact.in", "r");
	pg = fopen("fact.out", "w");

	fscanf(pf, "%d", &P);
	N = P * 5;
	if(P == 0)
		N = 1;
	else
		if(N > 5){
			k = power(5) - 1;
			printf("q = %d\n", q);
			N = N - 20 * (k - 1) * k / 2 - (count(q)) * 5 * k;
		}	
	fprintf(pg, "%d", N);

	fclose(pf);
	fclose(pg);

	return 0;
}