2015 Multi-University Training Contest 5

1009 MZL’s Border

字符串是可递归形式构造的,求解也是递归的;
但是递归时划分的三种情况,最终并没有做好化归

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.io.*;
import java.util.*;
import java.math.*;
public class Main{
static BigInteger f[] = new BigInteger[1005];
public static void main(String[] args){
f[1] = new BigInteger("1");
f[2] = new BigInteger("2");
for(int i = 3; i <= 1001; i++)
f[i] = f[i - 1].add(f[i - 2]);
Scanner cin = new Scanner(System.in);
int T = cin.nextInt();
int n;
BigInteger m;
for(int cas = 1; cas <= T; cas++){
n = cin.nextInt();
m = cin.nextBigInteger();
BigInteger mm = m.add(new BigInteger("1"));
int p = 0;
for(int i = 1; i <= 1001; i++){
if(f[i].compareTo(mm) > 0){
p = i;
break;
}
}
BigInteger ans = m.subtract(f[p - 2]);
System.out.println(ans.mod(new BigInteger("258280327")));
}

}
}