HDU 5351(MZL's Border-Java的BigInteger类)
2015-08-23 12:24
411 查看
MZL's Border
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1102 Accepted Submission(s): 353
[align=left]Problem Description[/align]
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
i s 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]'sLBorder
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|.
[align=left]Input[/align]
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.
[align=left]Output[/align]
The output consists of T
lines. Each has one number, meaning fibn'sLBorderm
modulo 258280327(=2×317+1).
[align=left]Sample Input[/align]
2 4 3 5 5
[align=left]Sample Output[/align]
1 2
[align=left]Author[/align]
SXYZ
[align=left]Source[/align]
2015 Multi-University Training Contest 5
[align=left]Recommend[/align]
wange2014 | We have carefully selected several similar problems for you: 5421 5420 5419 5418 5417
import java.io.*; import java.util.*; import java.math.*; public class Main{ static BigInteger f[] = new BigInteger[2000]; static BigInteger F = new BigInteger("258280327"); public static void main(String[] arg){ Scanner cin = new Scanner(System.in); f[2] = f[1]= new BigInteger("1"); for(int i=3;i<=1000;i++) f[i]=f[i-1].add(f[i-2]); int T=cin.nextInt(); while ((T--)>0) { int n=cin.nextInt(); BigInteger m = cin.nextBigInteger(); m=m.add(BigInteger.ONE); int i=1; while (m.compareTo(f[i])>=0) ++i; System.out.println((m.subtract(BigInteger.ONE).subtract(f[i-2])).mod(F)); } } }
相关文章推荐
- Java 线程详解
- java类型转换
- 基于Java的打包jar、war、ear包的作用与区别详解
- java-多线程-同步的优化
- 阿里校招-java研发 题目
- MyEclipse6.5注册机留档备查,有效期至2017年
- weblogic公布的项目用途myeclipse正常启动,点击startWeblogic.cmd报错解决方案
- Thinking in java 之:this关键字
- Java环境变量的配置、作用详解
- Thinking in java 之:构造器
- hadoop2对应的eclipse插件使用
- Java解析JSON文件的方法
- eclipse卡,相关优化配置
- JAVA 中BIO,NIO,AIO的理解
- Spring-(切面 ->切入点->通知)
- 在myeclipse中点击 deploy 旋钮,在弹出的Project Deployments筐中看不到刚导入的项目,无法部署
- MyEclipse导入项目报错Target runtime com.genuitec.runtime.generic.jee60 is not defined.
- Java记录 -10- 面向对象之封装续
- eclipse使用技巧一
- Java NIO原理图文分析及代码实现