- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSmallFactorials.java
More file actions
Latest commit
26 lines (22 loc) · 732 Bytes
/
Copy pathSmallFactorials.java
File metadata and controls
26 lines (22 loc) · 732 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
importjava.io.*;
importjava.math.BigInteger;
classSmallFactorials {
publicstaticvoidmain(Stringargs[]) throwsIOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
intnLines = Integer.parseInt(br.readLine());
for (inti = 0; i < nLines; i++) {
intnum = Integer.parseInt(br.readLine());
BigIntegerfact = factorial(num);
System.out.println(fact);
}
System.exit(0);
}
publicstaticBigIntegerfactorial(intn) {
BigIntegerbigNum = newBigInteger(Integer.toString(n));
returnfactorial(bigNum);
}
privatestaticBigIntegerfactorial(BigIntegern) {
if (n.equals(BigInteger.ONE)) returnn;
returnn.multiply(factorial(n.subtract(BigInteger.ONE)));
}
}