多校5-MZL's Border 分类: 比赛 2015-08-05 21:28 7人阅读 评论(0) 收藏
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) 收藏的更多相关文章
- 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 ...
- 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 ...
- 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...
- 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 ...
- 二分图匹配(KM算法)n^3 分类: ACM TYPE 2014-10-01 21:46 98人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> const ...
- 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 ...
- 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关键字的函 ...
- 跨服务器修改数据 分类: 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 ...
- 树莓派入手(烧写系统,调整分区,配置Java环境,串口GPS配置) 分类: Raspberry Pi 2015-04-09 21:13 145人阅读 评论(0) 收藏
原来的tf卡无故启动不起来,检查发现其文件系统分区使用率为0%. 数据全部丢失!!!!! 血的教训告诉我们备份文件系统的重要性,一切需要重头来.... 烧录系统 安装系统有两种方式, NOOBS工具安 ...
随机推荐
- 在Swift中整数以及浮点的格式化
1 整数的格式化 有的时候我们需要将整数输出为类似01,02,001,002这样的格式. 那么在swift中我们可以这样写 let i= let str = String(format:"% ...
- 树链剖分(单点更新,求区间最值,区间求和Bzoj1036)
1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5759 Solved: 2383 [Submi ...
- csuoj 1115: 最短的名字
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1115 1115: 最短的名字 Time Limit: 5 Sec Memory Limit: 6 ...
- prezi破解教程
http://www.joenchen.com/archives/998 http://www.joenchen.com/archives/945 Prezi Desktop 4.7.5免注册无时间限 ...
- 也不知怎么了LVS.SH找不到,网上搜了一篇环境搭配CENTOS下面的高可用 参考
系统环境: ************************************************************ 两台服务器都装了 CentOS-5.2-x86_64 系统 Vir ...
- (转)Aspone.Cells设置Cell数据格式 Setting Display Formats of Numbers and Dates
Setting Display Formats Using Microsoft Excel: Right-click on any desired cell and select Format Cel ...
- oracle数据库的归档模式
1:开发环境和测试环境中,数据库的日志模式和自动归档模式一般都是不设置的,这样有利于系统应用的调整,也免的生成大量的归档日志文件将磁盘空间大量的消耗. 2:生产环境时,将其设置为日志模式并自动归档就相 ...
- clock divider
一个clock的产生: 1) Clock source的选择: cgm_mux5(.clk_out, .clk_in0, .clk_in1, .clk_in2, .clk_in3, .clk_in4, ...
- 批量修改照片名称的shell脚本
代码这种经常完善的东西,其实是不太适合使用博客来发布的. 以下是一个批量修改照片名称的shell脚本: 事情是这样的,虽然手机拍的照片文件名是按照日期来确定的,但是是这种形式的 IMG_mmddYY_ ...
- 【NOIP模拟赛】正方形大阵
正方形大阵 [问题描述] [输入格式] 第一行一个正整数n代表询问次数. 接下来n行每行一个不超过八位的小数k代表一组询问. [输出格式] 输出共n行,代表每次询问的答案:如果有无数个交点 ...