-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10334 Ray Through Glasses.java
36 lines (36 loc) · 1.1 KB
/
10334 Ray Through Glasses.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
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
public class RayThroughGlasses
{
static BigInteger[] fibs = new BigInteger[1005];
public static void main(String[] args)throws IOException
{
//System.setIn(new FileInputStream(new File("1in.txt")));
//System.setOut(new PrintStream(new File("1out.txt")));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
fibs[0] = BigInteger.ONE;
fibs[1] = BigInteger.valueOf(2);
// preprocess(1001);
for(int i = 2; i < 1004; i++)
{
fibs[i] = fibs[i-1].add(fibs[i-2]);
}
String x;
StringBuilder sb = new StringBuilder("");
while((x = br.readLine()) != null && x.length()!=0)
{
sb.append(fibs[Integer.parseInt(x)]);
sb.append("\n");
}
System.out.print(sb);
}
// private static BigInteger preprocess(int i)
// {
// if(fibs[i] != null)
// return fibs[i];
// fibs[i] = preprocess(i - 1).add(preprocess(i - 2));
// return fibs[i];
// }
}