Hdu 5351 MZL's Border 2015ACM多校对抗赛第五场

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=5351

MZL's Border

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 942    Accepted Submission(s): 305


Problem Description
As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was playing with her favorite data structure, strings.

MZL is really like  Fibonacci Sequence , so she defines  Fibonacci Strings  in the similar way. The definition of  Fibonacci Strings  is given below.
  
  1)  fib1=b
  
  2)  fib2=a
  
  3)  fibi=fibi1fibi2, i>2
  
For instance,  fib3=ab, fib4=aba, fib5=abaab .

Assume that a string  s  whose length is  n  is  s1s2s3...sn . Then  sisi+1si+2si+3...sj  is called as a substring of  s , which is written as  s[i:j] .

Assume that  i<n . If  s[1:i]=s[ni+1:n] , then  s[1:i]  is called as a  Border  of  s . In  Borders  of  s , the longest  Border  is called as  s LBorder . Moreover,  s[1:i] 's  LBorder  is called as  LBorderi .

Now you are given 2 numbers  n  and  m . MZL wonders what  LBorderm  of  fibn  is. For the number can be very big, you should just output the number modulo  258280327(=2×317+1) .

Note that  1T100, 1n103, 1m|fibn| .
 

Input
The first line of the input is a number  T , which means the number of test cases.

Then for the following  T  lines, each has two positive integers  n  and  m , whose meanings are described in the description.
 

Output
The output consists of  T  lines. Each has one number, meaning  fibn 's  LBorderm  modulo  258280327(=2×317+1) .
 

Sample Input
  
  
2 4 3 5 5
 

Sample Output
  
  
1 2
 

Source
 

打表~~

import java.math.*;
import java.util.*;


public class Main {
    static BigInteger [] len  = new BigInteger[1100];
    static void init(){
        len[1]=BigInteger.ONE;
        len[2]=BigInteger.ONE;
        for(int i=3;i<=1000;i++)
            len[i]=len[i-1].add(len[i-2]);
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        init();
            Scanner cin = new Scanner(System.in);
            int T;
            T=cin.nextInt();
            while(T!=0)
            {
                T=T-1;
                int n = cin.nextInt();
//            BigInteger m = cin.nextBigInteger();
//            BigInteger a=BigInteger.ONE;
//                BigInteger b=BigInteger.ONE;
//                BigInteger c=a.add(b);
//                m=m.subtract(BigInteger.ONE);
//           while(m.compareTo(BigInteger.ZERO)>=0){
//                               if(m.compareTo(a)>=0)
//                                   m=m.subtract(a);
//                               else break;
//                      //  c=a.add(b);
//                           a=b;
//                               b=c;
//           c=a.add(b);
//           }
           BigInteger m = cin.nextBigInteger();
           BigInteger a = BigInteger.ONE;
           BigInteger b = BigInteger.ONE;
           BigInteger c = a.add(b);
           int i =0;
           while(m.compareTo(b)>0)
           {
           m=    m.subtract(b);
               i++;
               a = b;
               b = c;
               c = a.add(b);
           }
             //  System.out.println(m+" "+a+" "+" "+b+" "+c);
                BigInteger ans = m.add(a.subtract(BigInteger.ONE)).subtract(BigInteger.ONE);
                System.out.println(ans.mod(BigInteger.valueOf(258280327)));
            }
    }

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值