您的位置:首页 > 其它

[projecteuler]Factorial digit sum

2014-04-28 18:09 375 查看
题目:http://projecteuler.net/problem=20

代码:

import java.math.BigInteger;

public class Main{
public static void main(String args[])
{
BigInteger b = new BigInteger("1");

BigInteger temp = new BigInteger("2");

for(int i=2; i<=100; i++)
{
temp = BigInteger.valueOf(i);
b = b.multiply(temp);
}
int res = 0;
BigInteger qu[] = new BigInteger[2];
while(b.compareTo(new BigInteger("0")) != 0 )
{
qu = b.divideAndRemainder(new BigInteger("10"));
res += qu[1].intValue();
b = qu[0];
}

System.out.println(res);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息