zoukankan      html  css  js  c++  java
  • 多校5-MZL's Border 分类: 比赛 2015-08-05 21:28 7人阅读 评论(0) 收藏

    MZL’s Border
    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 909 Accepted Submission(s): 297

    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=fibi−1fibi−2, 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[n−i+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 1≤T≤100, 1≤n≤103, 1≤m≤|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
    2015 Multi-University Training Contest 5

    Recommend
    wange2014
    Java大数

    import java.math.*;
    import java.util.*;
    
    public class Main {
        public static void main(String[] args)
        {
            Scanner in = new Scanner (System.in);
            int i;
            BigInteger[] a = new BigInteger[1015];
            int t=in.nextInt();
            BigInteger ans;
            a[1] = BigInteger.valueOf(1);
            a[2] = BigInteger.valueOf(2);
            for(i=3;i<=1000;i++)
            {
                a[i]=a[i-1].add(a[i-2]);
            }
            while(t>0)
            {
                t--;
                int n=in.nextInt();
                BigInteger m = in.nextBigInteger();
                for(i=1;i<=1000;i++)
                {
                    if(m.compareTo(a[i])<0&&m.compareTo(a[i-1])>=0)
                    {
                        ans = m.subtract(a[i-2]).mod(BigInteger.valueOf(258280327));
                        System.out.println(ans);
                        break;
                    }
    
                }
            }
        }
    }
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    十二经络容易堵塞穴位
    考研英语词汇-乱序便携版-遗忘曲线
    分享一个硬核理工类科普节目:回到2049(12月17号取消置顶)
    191129
    191130
    191128
    191127
    191126
    191125
    微信公众号自定义菜单中添加图标(转)
  • 原文地址:https://www.cnblogs.com/juechen/p/4721926.html
Copyright © 2011-2022 走看看