HDU 5351 MZL's Border
来源:互联网 发布:caffe识别验证码 编辑:程序博客网 时间:2024/06/18 07:35
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 likeFibonacci 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 strings 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 thati<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 numbersn 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 that1≤T≤100, 1≤n≤103, 1≤m≤|fibn| .
MZL is really like
1)
2)
3)
For instance,
Assume that a string
Assume that
Now you are given 2 numbers
Note that
Input
The first line of the input is a number T , which means the number of test cases.
Then for the followingT lines, each has two positive integers n and m , whose meanings are described in the description.
Then for the following
Output
The output consists of T lines. Each has one number, meaning fibn 's LBorderm modulo 258280327(=2×317+1) .
Sample Input
24 35 5
Sample Output
12找找规律,然后模拟一下,注意有大数import java.io.*;import java.math.BigInteger;import java.util.*;public class Main{ public static void main(String args[]) { Scanner cin = new Scanner(System.in); BigInteger f[][] = new BigInteger[1005][3]; int i; f[0][1]=BigInteger.ZERO; f[0][2]=BigInteger.ZERO; f[1][1]=BigInteger.ZERO; f[1][2]=BigInteger.ZERO; f[0][0]=BigInteger.ONE; f[1][0]=BigInteger.ONE; for (i=2;i<=1000;i++) { f[i][0]=f[i-1][0].add(f[i-2][0]); f[i][1]=f[i-1][2].subtract(f[i-1][1]); f[i][2]=f[i][1].add(f[i][0]).subtract(BigInteger.ONE); } int T=cin.nextInt(); for(;T>=1;T--) { int n; BigInteger m; n=cin.nextInt(); m=cin.nextBigInteger(); for(i=1;i<=1000;i++) { if(m.compareTo(f[i][0])<1) { m=f[i][1].add(m).subtract(BigInteger.ONE); m=m.mod(BigInteger.valueOf(258280327)); System.out.println(m); break; } else m=m.subtract(f[i][0]); } } }}
0 0
- HDU 5351 MZL's Border
- HDU 5351 MZL's Border
- HDU 5351 MZL's Border
- [hdu 5351] MZL's Border
- HDU 5351 MZL's Border(大数+规律)
- hdu 5351 MZL's Border (大数)
- HDU 5351 MZL's Border(规律)
- 109.hdu--5351--MZL's Border
- HDU 5351 MZL's Border(找规律)
- HDU 5351 MZL's Border(java 找规律)
- hdu 5351 MZL's Border(打表+高精度)
- HDU 5351 MZL's Border(找规律+高精度)
- HDU 5351(MZL's Border-Java的BigInteger类)
- 多校-HDU 5351 MZL's Border 数学规律
- Hdu 5351 MZL's Border (找规律+Java高精度)
- HDOJ 5351 MZL's Border 找规律
- HDU5351 MZL's Border
- HDU 5351 MZL's Border(2015多校第五场第9题) 写长串找规律
- POJ 3620 Avoid The Lakes(dfs)
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings
- HDU 5344
- 剑指Offer面试题24(Java版):二叉搜索树的后序遍历序列
- Android复习笔记(10) -对话框的使用
- HDU 5351 MZL's Border
- HDU 2546 饭卡
- 多线程1
- UVa 567 Risk (Floyd+任意两点最短路)
- C语言编程入门——综合练习(三)学生管理系统
- 正则表达式30分钟入门教程
- JAVA学习笔记(一)
- Oracle 11g R2+RAC+ASM+redhat安装详解1
- SVN 版本控制