Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 462 Accepted Submission(s): 127
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 5 public class Main { 6 7 static BigInteger[] fib1 = new BigInteger[1010]; 8 static BigInteger[] fib2 = new BigInteger[1010]; 9 static BigInteger[] fib3 = new BigInteger[1010]; 10 public static void main(String []args) 11 { 12 fib1[1] = new BigInteger("2"); 13 fib1[2] = new BigInteger("2"); 14 fib2[1] = BigInteger.ONE; fib2[2] = BigInteger.ONE; 15 fib3[1] = BigInteger.ZERO; fib3[2] = BigInteger.ONE; 16 17 for(int i = 3; i <= 1005; i++) 18 { 19 fib1[i] = fib1[i-1].add(fib1[i-2]); 20 fib2[i] = fib2[i-1].add(fib2[i-2]); 21 } 22 for(int i = 3; i <= 1005; i++) 23 { 24 fib3[i] = fib3[i-1].add(fib2[i-1]); 25 } 26 27 Scanner in = new Scanner(System.in); 28 int T = in.nextInt(), maxN = 0; 29 for(int cast = 1; cast <= T; cast++) 30 { 31 int n; BigInteger m; 32 n = in.nextInt(); 33 m = in.nextBigInteger(); 34 int i; 35 for(i = 1; i <= 1005; i++) 36 { 37 if(m.compareTo(fib1[i]) == 1) 38 { 39 m = m.subtract(fib1[i]); 40 } 41 else break; 42 } 43 if(m.compareTo(fib1[i].divide(new BigInteger("2"))) == 1) 44 { 45 m = m.subtract(fib1[i].divide(new BigInteger("2"))); 46 BigInteger ans = m.add(fib3[i]); 47 ans = ans.subtract(BigInteger.ONE); 48 ans = ans.remainder(new BigInteger("258280327")); 49 System.out.println(ans.toString()); 50 } 51 else 52 { 53 BigInteger ans = m.add(fib3[i]); 54 ans = ans.subtract(BigInteger.ONE); 55 ans = ans.remainder(new BigInteger("258280327")); 56 System.out.println(ans.toString()); 57 } 58 } 59 } 60 }
原文:http://www.cnblogs.com/titicia/p/4703064.html