fzu 1050 Number lengths

题目链接:fzu 1050 Number lengths


题目大意:计算n!有多少位数。


解题思路:ans = log10(n!) =  ∑(1≤i≤n)log(i).


#include 
#include 

const int N = 1000005;
int n, d[N];

void init() {
	double sum = 0;
	for (int i = 1; i < N; i++) {
		sum += log10((double)i);
		d[i] = (int)sum;
	}
}

int main () {
	init();
	while (scanf("%d", &n) == 1) {
		printf("%d\n", d[n] + 1);
	}
	return 0;
}


你可能感兴趣的:(GRADE:D,FZU,数学-基础)