- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
Latest commit
32 lines (23 loc) · 810 Bytes
/
Copy pathMain.java
File metadata and controls
32 lines (23 loc) · 810 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
importjava.math.BigInteger;
/*
@author: mc-es
Problem 15
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20×20 grid?
Answer: 137846528820
*/
publicclassMain {
publicstaticvoidmain(String[] args) {
// calculate iterative permutation
BigIntegerbigInteger = calculateFact(40).divide(calculateFact(20).multiply(calculateFact(20)));
System.out.println(bigInteger);
}
// calculate factorial
publicstaticBigIntegercalculateFact(intnumber) {
BigIntegerfactorial = BigInteger.ONE;
for (inti = 1; i <= number; i++) {
factorial = factorial.multiply(BigInteger.valueOf(i));
}
returnfactorial;
}
}