-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1022.java
31 lines (29 loc) · 852 Bytes
/
1022.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
import java.math.BigInteger;
import java.util.*;
public class Main {
private static Scanner in;
public static void main(String[] args) {
in = new Scanner(System.in);
long n=in.nextLong();
Main m =new Main();
if(n%2040==0){
System.out.print(0);
}else{
BigInteger res = m.fib(n%2040);
System.out.print((res.divideAndRemainder(new BigInteger("2010")))[1]);
}
}
BigInteger fib(long n){
if(n==1 || n==2){
return new BigInteger("1");
}else{
BigInteger pnum=new BigInteger("1");
BigInteger cnum=new BigInteger("1");
for(int i=3;i<=n;i++){
cnum= cnum.add(pnum);
pnum =cnum.subtract(pnum);
}
return cnum;
}
}
}