-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp020.java
46 lines (37 loc) · 961 Bytes
/
p020.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.math.*;
public class problem_20{
public static void main(String arg[]){
BigInteger fac = Factorial(100);
long sun = 0;
System.out.println(Total(fac));
}
public static BigInteger Factorial(int range){
BigInteger bigNum,bigi;
bigNum = new BigInteger("1");
bigi = new BigInteger("1");
for(int i = 1; i <=range; i++){
bigi = BigInteger.valueOf(i);
bigNum = bigNum.multiply(bigi);
}
//System.out.println("100!: " + bigNum);
return bigNum;
}
public static BigInteger Total(BigInteger f){
BigInteger bigTmp,bigSum,bigZero;
bigTmp = new BigInteger("10");
bigSum = new BigInteger("0");
bigZero = new BigInteger("0");
while(true){
bigSum = bigSum.add(f.remainder(bigTmp));
//sum += (f.remainder(bigTmp)).longValue();
//System.out.println(sum);
f = f.divide(bigTmp);
System.out.println(bigSum);
if( f.equals(bigZero)){
break;
}
}
//System.out.println(bigSum);
return bigSum;
}
}