-
Notifications
You must be signed in to change notification settings - Fork 4
/
p020.java
44 lines (33 loc) · 860 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
import java.math.*;
/**
*
* @author gouravrusiya
*
*/
public class p020 {
public static void main(String[] args) {
// TODO Auto-generated method stub
long startTime = System.currentTimeMillis();
BigInteger fact = new BigInteger("1");
int n = 1000000;
int sum =0;
for (BigInteger bi = BigInteger.valueOf(n);
bi.compareTo(BigInteger.ZERO) > 0;
bi = bi.subtract(BigInteger.ONE)) {
fact = fact.multiply(bi);
}
//System.out.println(fact);
String str = new String(fact.toString());
//System.out.println(str);
for(int i=0;i<str.length();i++)
{
String s;
s = ""+str.charAt(i);
int x = Integer.parseInt(s);
sum = sum + x;
}
System.out.println(sum);
long endTime = System.currentTimeMillis();
System.out.println("Took "+(endTime - startTime) + " ms");
}
}