(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: ...
随机推荐
- Coursera课程《大家的编程》(Python入门)中课程目录
Getting Started with Python Getting Started with Python is the first course in the specialization Py ...
- jenkins error: "no valid crumb was included in the request"
一.问题描述(Problem Description): 在jenkins中创建新任务时候选择“拷贝已存在任务”,点击OK,跳转到下一步时候弹出如下错误信息:"No valid crumb ...
- [转载] java的书
1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Eckel 的<Thinking in Java >.它是一本写的相当深刻的技术书籍,Java 语言基 ...
- 怎样通过terminal得到AWS EC2 instance的ip
可得到private ip,也是本地的ip.事实上通过ifconfig也能得到: GET http://169.254.169.254/latest/meta-data/local-ipv4 公共ip ...
- [Usaco2006 Nov]Roadblocks第二短路
贝茜把家搬到了一个小农场,但她常常回到FJ的农场去拜访她的朋友.贝茜很喜欢路边的风景,不想那么快地结束她的旅途,于是她每次回农场,都会选择第二短的路径,而不象我们所习惯的那样,选择最短路. 贝茜所在的 ...
- C语言编译器不检查数组下标越界
这两天被人问了一个问题说假如C/C++访问下表越界的数组元素会报错么,于是充满好奇心的我动手试了一下,WTF,果然没有报错,但是会给程序带来莫名其妙的结果(比如十次的循环但是变成了死循环,但八次却可以 ...
- [转]一键安装藏隐患,phpStudy批量入侵的分析与溯源
一.前言 近日,腾讯安全云鼎实验室监测到大量主机被入侵并添加了一个名为“vusr_dx$”的隐藏帐号:同时,云鼎实验室还监测到此类帐号被大量创建的同时存在对应帐号异地登录的情况. Windows 的帐 ...
- python 抓取alexa数据
要抓取http://www.alexa.cn/rank/baidu.com网站的排名信息:例如抓取以下信息: 需要微信扫描登录 因为这个网站抓取数据是收费,所以就利用网站提供API服务获取json信息 ...
- IIS-将iis直接指向.net代码会出现错误
这是由于没有bin文件导致的,将bin文件加上之后就可以了.
- 如何利用SQL语句求日期的时间差值,并汇总网上的一些信息
MySQL本身提供了 DATEDIFF 函数,用来计算时间差. 手册:http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.ht ...