(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: ...
随机推荐
- svn(subversion)版本控制系统学习与理解
定义:Apache Subversion(简称SVN,svn),一个开放源代码的版本控制系统,相较于RCS.CVS,它采用了分支管理系统,它的设计目标就是取代CVS. 从这段话,我们可以得到四点信息: ...
- Android之等比例显示图片
在android中,由于密度的影响,如果想得到图片的宽高是不行的,具体为什么我就大概说一下,具体的请搜索度娘或者古哥吧. 原因是如果你把图片放在drawable-mdpi里,而手机是属于drawabl ...
- jquery、js获取table,遍历输出tr中各个td的内容。
首先,依赖jquery.. $('#btntb').click(function(){ $('#tab tr').each(function(i){ // 遍历 tr $(this).children ...
- kafak-python函数使用详解
Consumer是非线程安全的 Kafka只保证消息不漏,即at lease once,而不保证消息不重.关键点:假如consumer挂了重启,那它将从committed offset位置(告诉ser ...
- kafka存储机制
kafka存储机制 @(博客文章)[storm|大数据] kafka存储机制 一关键术语 二topic中partition存储分布 三 partiton中文件存储方式 四 partiton中segme ...
- C++ Explicit Constructors(显式构造函数)
C++ 为类(Class)提供了许多默认函数.如果自己没有申明,编译器会为我们提供一个copy构造函数.一个copy assignment操作符和一个析构函数.此外,如果没有申明任何构造函数,编译器会 ...
- 几个不同版本的framework改进
一些主要的演变过程及改进,还有很多部分不可能一一列出,下面是从1.1到4.0的一些主要改进: 一..NET Framework 1.1版本 1.ASP.NET移动控件 2.ADO.NET的改动 添加S ...
- 分享七个绚丽夺目的JQuery导航(还有苹果、猪八戒等),有图有真相
今天来一起看看几个个人觉得比较好的导航.有好几个导航是仿的,比如仿苹果.仿猪八戒等等,但仿得还都不错.也有不少是基于jQuery的.特别是像我这样的懒人,就可以在这些基础上修修改改作为自己网站项目的导 ...
- 利用CSS、JavaScript及Ajax实现图片预加载的三大方法及优缺点分析
预加载图片是提高用户体验的一个很好方法.图片预先加载到浏览器中,访问者便可顺利地在你的网站上冲浪,并享受到极快的加载速度.这对图片画廊及图片占据很大比例的网站来说十分有利,它保证了图片快速.无缝地发布 ...
- 给 TextBlock 加 ToolTip
<TextBlock ToolTip="{Binding RelativeSource={RelativeSource Self},Path=Text}" Text=&quo ...