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. mysql之innodb_buffer_pool

    1>.mysqld重启之后,innodb_buffer_pool几乎是空的,没有任何的缓存数据.随着sql语句的执行,table中的数据以及index 逐渐被填充到buffer pool里面,之 ...

  2. hdu 2528 Area

    2014-07-30 http://acm.hdu.edu.cn/showproblem.php?pid=2528解题思路: 求多边形被一条直线分成两部分的面积分别是多少.因为题目给的直线一定能把多边 ...

  3. SQL 存储和触发器

    存储过程:就像函数一样的会保存在数据库中-->可编程性 --> 存储过程 创建存储过程:create proc JiaFa--需要的参数@a int,@b intas --存储过程的内容 ...

  4. ubuntu安装jdk遇到的问题:cannot execute binary file

    安装完jdk,配置好环境变量出现如下状况: cannot execute binary file 问题原因: jdk的位数与ubuntu的系统位数不一致 jdk 64位 ubuntu 32位 然后通过 ...

  5. 如何使用highmaps制作中国地图

    如何使用highmaps制作中国地图 文章目录 Highmaps 所需文件 地图初始化代码 highmaps 渲染讲解 highmaps 中国各城市坐标的json文件 highmaps 线上DEMO ...

  6. 夺命雷公狗—angularjs—10—angularjs里面的内置函数

    我们没学一门语言或者框架,几乎里面都有各自的语法和内置函数,当然,强悍的angularjs也不例外,他的方法其实常用的没多少,因为很多都可以用源生jis几乎都能完成一大部分.. <!doctyp ...

  7. SQL Server session故障排查

    --根据作业名 查找session id select a.spid,a.blocked,b.name,substring(replace(a.PROGRAM_NAME,'SQLAgent - TSQ ...

  8. [tp3.2.1]让默认页面: 加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.

    QQ:让index.php默认加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.AA:复制index.php命名为admin.php复制(新建)A ...

  9. 关于事件触发的一个小tips

    今天看到如下代码 window.globalEvent.bind('hotelHotTableRendered', function () { $('#hotelHotTd a').each(func ...

  10. linux内核中jiffies的回绕问题【转】

    本文转载自:http://blog.csdn.net/yuanlulu/article/details/6019862 ======================================== ...