-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFactorialDigitSum.java
More file actions
32 lines (29 loc) · 866 Bytes
/
FactorialDigitSum.java
File metadata and controls
32 lines (29 loc) · 866 Bytes
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int bi;
int n = sc.nextInt();
while(n!=0){
bi = sc.nextInt();
BigInteger fact = new BigInteger("1");
BigInteger temp = new BigInteger("1");
BigInteger sum = new BigInteger("0");
for(int i=1;i<=bi;i++){
fact = fact.multiply(BigInteger.valueOf(i));
}
while(fact.signum() > 0){
temp = fact.mod(BigInteger.TEN);
sum = sum.add(temp);
fact = fact.divide(BigInteger.TEN);
}
System.out.println(sum);
n--;
}
sc.close();
}
}