标签:i++ blog ret while can lan std das bsp
我直接用 long long 暴力,居然过了
——代码
#include <cstdio>
int n;
long long x, ans = 1;
int main()
{
	int i;
	scanf("%d", &n);
	for(i = 1; i <= n; i++)
	{
		x = i;
		while(!(x % 10)) x /= 10;
		x %= 1000000000;
		ans *= x;
		while(!(ans % 10)) ans /= 10;
		ans %= 1000000000;
	}
	printf("%lld\n", ans % 10);
	return 0;
}
有个比较好理解的方法是
因为末尾的0是由因子 2 和 因子 5 乘出来的
所以取出每一个数的因数 2 和 5,两者相抵消,最后再把没有抵消掉的乘回去
标签:i++ blog ret while can lan std das bsp
原文地址:http://www.cnblogs.com/zhenghaotian/p/7049956.html