Cod sursa(job #2199044)

Utilizator dan.stefanescuDan Stefanescu dan.stefanescu Data 26 aprilie 2018 14:42:24
Problema Factorial Scor 20
Compilator c Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <stdio.h>

int exponent(int a,int b) {
	int s = 0;

	while(a%b==0) {
		s++;
		a=a/b;
	}

	return s;
}

int main() {

	FILE *f = fopen("fact.in","rt");
	FILE *g = fopen("fact.out","wt");
	int n;

	fscanf(f,"%d",&n);
	printf("%d\n",n);

	int i=1;
	int twos = 0;
	int fives = 0;

	while(1) {
		twos += exponent(i,2);
		fives += exponent(i,5);

		if(twos>=n && fives>=n) {
			break;
		}

		// printf("i:%d  twos:%d  fives:%d\n",i,twos,fives);
		i++;
	}

	fprintf(g, "%d", i);
	fclose(f);
	fclose(g);
	return 0;
}