1. 求100!的结果的各位数之和为多少?
如:5!=5*4*3*2*1=120,那么他们的和为1+2+0=3
<span style="white-space:pre"> </span>@Test
public void test1() {
BigInteger fact = getFact(100);
System.out.println(getSum(fact));
}
public BigInteger getFact(int n) {
if (n == 1) {
return new BigInteger("1");
}
return getFact(n - 1).multiply(new BigInteger(n + ""));
}
public int getSum(BigInteger num) {
String fact = num.toString();
int sum = 0;
for (int i = 0; i < fact.length(); i++) {
sum += Integer.parseInt(fact.charAt(0) + "");
}
return sum;
}