Cod sursa(job #322558)

Utilizator marinMari n marin Data 9 iunie 2009 09:21:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <stdio.h>
#define DIM 500000011

int p,u,P,m;

int zero(int n) {
	int c = 5;	
	int r = 0;
	int x;
	while (x = n/c) {
		r+=x;
		c*=5;
	}
	return r;
}

int main(){
	FILE *f = fopen("fact.in","r");
	fscanf(f,"%d",&P);
	fclose(f);
	
	
	p = 1;
	u = 5*P;
	while (p<=u) {
		m = p+(u-p)/2;
		if (zero(m)>=P)
			u = m-1;
		else
			p = m+1;
	}
	
	FILE *g = fopen("fact.out","w");
	if (zero(p) == P)
		fprintf(g,"%d",p);
	else
		fprintf(g,"%d",-1);
	fclose(g);
	return 0;
}