-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLemonTale.java
56 lines (40 loc) · 1.26 KB
/
LemonTale.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
47
48
49
50
51
52
53
54
55
56
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class LemonTale
{
protected static BigInteger[] kbanacci(int n, int k) {
BigInteger[] cache = new BigInteger[k+1];
cache[0] = new BigInteger("1");
cache[1] = new BigInteger("1");
if (k > 1) {
cache[2] = new BigInteger("2");
if (k > 2) {
BigInteger two = new BigInteger("2");
for (int i = 3; i <= k; i++) {
cache[i] = cache[i-1].multiply(two);
}
}
}
for (int i = 0; i < n; i++) {
BigInteger x = cache[k].subtract(cache[0]).add(cache[k]);
for (int j = 1; j <= k; j++) {
cache[j - 1] = cache[j];
}
cache[k] = x;
}
return cache;
}
public static void main(String argv[]) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
int k = in.nextInt();
if (k == 0) {
System.out.println("1");
return;
}
BigInteger[] s = kbanacci(n+1, k+1);
System.out.println(s[0].toString());
}
}