HDU 5351 MZL's Border(规律)

MZL‘s Border

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 835    Accepted Submission(s): 268

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

点击打开链接

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

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        BigInteger[] a=new BigInteger[1055];
        BigInteger[] b=new BigInteger[1055];
        a[1]=BigInteger.valueOf(1);
        a[2]=BigInteger.valueOf(2);
        for(int i=3;i<1050;++i)
        {
            a[i]=a[i-1].add(a[i-2]);
        }
        while(N>0)
        {
            N--;
            int n=sc.nextInt();
            BigInteger m = sc.nextBigInteger();

            for(int i=1;i<1050;++i)
            {
                if( m.compareTo(a[i+1].subtract(BigInteger.valueOf(1)))<0 && m.compareTo(a[i].subtract(BigInteger.valueOf(1)))>=0 )
                {

                     System.out.println((m.subtract(a[i-1])).mod(BigInteger.valueOf(258280327)));
                     break;
                }

            }
        }
    }
}

版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。

HDU 5351 MZL's Border(规律)

时间: 2024-10-17 21:23:46

HDU 5351 MZL's Border(规律)的相关文章

HDU 5351 MZL&#39;s Border(找规律+高精度)

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 895    Accepted Submission(s): 287 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was p

HDU 5351 MZL&#39;s Border(java 找规律)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5351 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 defin

HDU 5351——MZL&#39;s Border——————【高精度+找规律】

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 944    Accepted Submission(s): 306 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl

hdu 5351 MZL&#39;s Border 打表+高精度

MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 462    Accepted Submission(s): 127 Problem Description As is known to all, MZL is an extraordinarily lovely girl. One day, MZL was pl

多校-HDU 5351 MZL&#39;s Border 数学

f[1] = 'b', f[2] = 'a', f[i] = f[i - 1] + f[i - 2] 斐波那契数列的字符串,给你n和m,前m位中,最长的前缀等于后缀的长度是多少.1≤n≤1000, 1≤m≤length(f[n]) 规律题,虽然我不知道为什么. 1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 public class Main{ 5 //Scanner cin = Scanner(System.i

HDOJ 5351 MZL&#39;s Border 找规律

打出前i个串的kmp的fail指针: p: ab 0 0 0 p: aba 0 0 0 1 p: abaab 0 0 0 1 1 2 p: abaababa 0 0 0 1 1 2 3 2 3 p: abaababaabaab 0 0 0 1 1 2 3 2 3 4 5 6 4 5 p: abaababaabaababaababa 0 0 0 1 1 2 3 2 3 4 5 6 4 5 6 7 8 9 10 11 7 8 p: abaababaabaababaababaabaababaabaab

hdu5351 MZL&#39;s Border(规律题,java)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 905    Accepted Submission(s): 295 Problem Description As is known to all,

hdu5351(2015多校5)--MZL&#39;s Border(打表,,找规律)

题目链接:点击打开链接 题目大意:给出b1 = 'b' , b2 = 'a' , bi = b(i-1)b(i-2),将i-1和i-2链接起来,记录一个串的s[1-i] 和s[n-i+1-n]相同的话 Border,当i为最长是为LBorder,现在给让求在bn这个串上的前m个字符组成的子串的LBorder 通过计算可以发现,b字符串的前缀都是相同的,所以只要求出m的LBorder就行,和n是无关的,打表找出规律,找出对应不同的m,LBorder的值,因为存在大数,用java写 dp[i]第i层

hdu 5344 MZL&#39;s xor(数学之异或)

Problem Description MZL loves xor very much.Now he gets an array A.The length of A is n.He wants to know the xor of all (Ai+Aj)(1≤i,j≤n) The xor of an array B is defined as B1 xor B2...xor Bn Input Multiple test cases, the first line contains an inte