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;
} }
}
}
}

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

多校5-MZL's Border 分类: 比赛 2015-08-05 21:28 7人阅读 评论(0) 收藏的更多相关文章

  1. Hiking 分类: 比赛 HDU 函数 2015-08-09 21:24 3人阅读 评论(0) 收藏

    Hiking Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Subm ...

  2. Hdu 1507 Uncle Tom's Inherited Land* 分类: Brush Mode 2014-07-30 09:28 112人阅读 评论(0) 收藏

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏

    Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...

  4. Safecracker 分类: HDU 搜索 2015-06-25 21:12 12人阅读 评论(0) 收藏

    Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...

  5. 二分图匹配(KM算法)n^3 分类: ACM TYPE 2014-10-01 21:46 98人阅读 评论(0) 收藏

    #include <iostream> #include<cstring> #include<cstdio> #include<cmath> const ...

  6. Segment Tree with Lazy 分类: ACM TYPE 2014-08-29 11:28 134人阅读 评论(0) 收藏

    #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; stru ...

  7. C++ Virtual介绍 分类: C/C++ 2015-06-16 21:36 26人阅读 评论(0) 收藏

    参考链接:http://www.cnblogs.com/xd502djj/archive/2010/09/22/1832912.html 学过C++的人都知道在类Base中加了Virtual关键字的函 ...

  8. 跨服务器修改数据 分类: SQL Server 2014-08-21 21:24 316人阅读 评论(0) 收藏

     说明: 两个服务器: 192.168.0.22   A 192.168.0.3     B 数据库备份在A上 数据库在B上 在A上写: exec sp_addlinkedserver   'ITSV ...

  9. 树莓派入手(烧写系统,调整分区,配置Java环境,串口GPS配置) 分类: Raspberry Pi 2015-04-09 21:13 145人阅读 评论(0) 收藏

    原来的tf卡无故启动不起来,检查发现其文件系统分区使用率为0%. 数据全部丢失!!!!! 血的教训告诉我们备份文件系统的重要性,一切需要重头来.... 烧录系统 安装系统有两种方式, NOOBS工具安 ...

随机推荐

  1. DNS域名解析

    之前用的是DNSPOD.CN的解析,没什么问题. 因为想根据不同国家做服务器解析(欧洲,亚洲,美国) 然后就转到DNSPOD.com里面有按国家来分的. 但是欧洲那边反应,每天断断续续会不能访问网站. ...

  2. 0428—Scrum团队成立及《构建之法》第六、七章读后感

    5.Scrum团队成立 5.1 团队名称:喳喳 团队目标:突破渣渣 团队口号:吱吱喳喳 团队照: 5.2 角色分配 产品负责人: 112冯婉莹 Scrum Master:109张鑫相 PM项目经理:1 ...

  3. XML工程配置文件的读写

    TinyXML是一个开源的解析XML的解析库,能够用于C++,能够在Windows或Linux中编译,使用TinyXML进行C++ XML解析,使用简单,容易上手.这个解析库的模型通过解析XML文件, ...

  4. .vimrc文件配置及航意

    1.  vimrc文件常见语句释义 设定 tab 的位置          :set tabstop=4 输入 tab 时自动将其转化为空格          :set expandtab       ...

  5. Python学习总结8:文件模式及操作方法汇总

    文件操作之前需要文件保证文件存在,并且将文件open os.mknod("test.txt")        创建空文件 fp = open("test.txt" ...

  6. jni

    http://www.cnblogs.com/likwo/archive/2012/05/21/2512400.html

  7. js同步访问后台资源

    $.ajax( {  type : 'post',  url : url,  data : data,  async : false,//false代表只有在等待ajax执行完毕后才执行window. ...

  8. small details

    1.操作数据时,一般能入库就入库,或者用xml文件,用文件操作比较复杂

  9. url传参

    1.两种url形式传参index.php/action/function/id/2   这种模式下:$_GET[action]就是function,$_GET[id]就是2

  10. Java throw:异常的抛出怎么回事

    到目前为止,你只是获取了被Java运行时系统抛出的异常.然而,程序可以用throw语句抛出明确的异常.Throw语句的通常形式如下:    throw ThrowableInstance;这里,Thr ...