(CF#257)B. Jzzhu and Sequences
Jzzhu has invented a kind of sequences, they meet the following property:
You are given x and y,
please calculate fn modulo 1000000007 (109 + 7).
The first line contains two integers x and y (|x|, |y| ≤ 109).
The second line contains a single integer n (1 ≤ n ≤ 2·109).
Output a single integer representing fn modulo 1000000007 (109 + 7).
2 3
3
1
0 -1
2
1000000006
In the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6).
本来9点的CF,今天有学姐来,讲到了9点半,这题最后没注意坑点,最后判的时候还wa了,掉了100分,蛋疼中
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1100;
const int M=1000000007;
int a[maxn];
int main()
{
int x,y,n;
while(cin>>x>>y>>n)
{
a[1]=x;
a[2]=y;
int len=0,t;
for(int i=3;;i++)
{
a[i]=a[i-1]-a[i-2];
if(a[i]==a[2]&&a[i-1]==a[1]&&i>=4)
{
len=i-2;
break;
}
if(i>=n)
break;
}
if(len)
{
// cout<<"len:"<<len<<endl;
t=(n-1)%len+1;
}
else
t=n;
if(a[t]>0)
cout<<a[t]%M<<endl;
else
{
while(a[t]<0)
a[t]+=M;
cout<<a[t]%M<<endl;
}
}
return 0;
}
看了别人的想法,我的还是太狭隘了。我仅仅知道找规律,别人找的规律更详细。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=(1e9)+7;
int a[6]; int main()
{
int x,y,n;
while(cin>>x>>y>>n)
{
a[1]=(x+M)%M;
a[2]=(y+M)%M;
a[3]=(a[2]-a[1]+M)%M;
a[4]=(-x+M)%M;
a[5]=(-y+M)%M;
a[0]=(a[1]-a[2]+M)%M;
cout<<(a[n%6]+M)%M<<endl;
}
}
(CF#257)B. Jzzhu and Sequences的更多相关文章
- (CF#257)A. Jzzhu and Children
There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number al ...
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)
题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...
- CodeForces 450B Jzzhu and Sequences (矩阵优化)
CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...
- Codeforces Round #257 (Div. 2 ) B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CF450B Jzzhu and Sequences(矩阵加速)
CF450B Jzzhu and Sequences 大佬留言:这.这.不就是矩乘的模板吗,切掉它!! You are given xx and yy , please calculate $f_{n ...
- CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂
题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...
- codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)
题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces450 B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 数学 找规律 Jzzhu and Sequences
A - Jzzhu and Sequences Jzzhu has invented a kind of sequences, they meet the following property: ...
随机推荐
- ConcurrentDictionary AddOrUpdate
var sessionId = a.Session.SessionID.ToString(); userDic.AddOrUpdate( authUser.UserId, sessionId, (ke ...
- .NET:CLR via C#The Managed Heap and Garbage Collection
Allocating Resources from the Managed Heap The CLR requires that all objects be allocated from the m ...
- SVN中的Trunk、Tag、Brance的用法
在SVN中Branch/tag在一个功能选项中,在使用中也往往产生混淆.在实现上,branch和tag,对于svn都是使用copy实现的,所以他们在默认的权限上和一般的目录没有区别.至于何时用tag, ...
- 关于Themleaf学习总结
此篇记录学习Themleaf测试的相关用例: study01 Thymeleaf 的HelloWorld级别的例子 简单介绍Thymeleaf的工作流程 study02 使用spring.thymel ...
- strdup实现
char * strdup(char *str) { char * strNew; assert(str != NULL); strNew = (); strcpy(strNew,str); retu ...
- 中国计算机学会CCF推荐国际学术会议和期刊目录(PDF版,2015年)
total: CCF推荐国际学术会议和期刊目录(下载) parts: 点击下载: 计算机体系结构并行与分布计算存储系统.pdf 点击下载: 计算机网络.pdf 点击下载: 网络与信息安全.pdf ...
- IIS HTTP 错误 404.17 - Not Found 解决方法
错误提示如下图: 出现这种情况的原因通常是因为先安装了Framework,后安装的IIS: 运行cmd,输入: C:\Windows\Microsoft.NET\Framework\V4.0.30 ...
- go语言基础之map介绍和使用
1.map介绍 Go语言中的map(映射.字典)是一种内置的数据结构,它是一个无序的key—value对的集合,比如以身份证号作为唯一键来标识一个人的信息. 2.map示例 map格式为: map[k ...
- Android中的树状(tree)列表
树状列表前端挺常用的,还有人专门写过Ztree,Android中有的时候也需要使用到树状列表,上篇文章写了一下ExpandableListView,ExpandableListView最多支持两级结构 ...
- supervisord不重启更新配置文件
二.更新新的配置到supervisord supervisorctl update 1 三.重新启动配置中的所有程序 supervisorctl reload