HDU 5351 MZL's Border(规律)
来源:互联网 发布:犀牛软件材质贴图 编辑:程序博客网 时间:2024/06/11 12:50
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 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
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; } } } }}
0 0
- HDU 5351 MZL's Border(规律)
- 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高精度)
- 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
- HDOJ 5351 MZL's Border 找规律
- HDU 5351 MZL's Border(大数 + 找规律)——2015 Multi-University Training Contest 5
- hdu 5351 MZL's Border(打表+高精度)
- 109.hdu--5351--MZL's Border
- HDU 5351 MZL's Border(2015多校第五场第9题) 写长串找规律
- HDU 5351(MZL's Border-Java的BigInteger类)
- android开机启动某个应用
- nginx upstream的几种配置方式
- hdu 5351 MZL's Border (大数)
- 从贝叶斯方法谈到贝叶斯网络
- Linux隐匿和清除的几条命令-TOOLS-20150804
- HDU 5351 MZL's Border(规律)
- android_移植memtester
- 关于BMP文件、Opencv Image(Mat)、Matlab mwArr的buffer结构
- 图片缩放
- 低级绕过手段
- 如何在Android开发中让你的代码更有效率
- 64bit需要做的改变
- linux命令--------------top
- Undefined symbols for architecture i386:和"_OBJC_CLASS_$_xx", referenced from:问题解决方法