码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj5351

时间:2015-08-04 22:36:59      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static BigInteger fib[] = new BigInteger[1005];
    static BigInteger one = new BigInteger("1");
    public static void fibm(){
        fib[1] = fib[2] = one;
        for( int i = 3; i <= 1000; ++i){
            fib[i] = fib[i-1].add(fib[i-2]);
        }
    }
    static BigInteger MOD = new BigInteger("258280327");
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        fibm();
        int T;
        int n;
        T = cin.nextInt();
        BigInteger m, res;
        while(T>0){
            n = cin.nextInt();
            m = cin.nextBigInteger();
            int i;
            for( i = 1; i < 1000;i++){
                if(m.add(one).compareTo(fib[i])<0)
                    break;
            }
            res = m.subtract(fib[i-2]);
            res = res.mod(MOD);
            System.out.println(res);
            T--;
        }
    }

}

hdoj5351

标签:

原文地址:http://www.cnblogs.com/blueprintf/p/4703231.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!