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).

Input

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

Output a single integer representing fn modulo 1000000007 (109 + 7).

Sample test(s)
input
2 3
3
output
1
input
0 -1
2
output
1000000006
Note

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的更多相关文章

  1. (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 ...

  2. 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 ...

  3. CodeForces 450B Jzzhu and Sequences (矩阵优化)

    CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...

  4. 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 ...

  5. CF450B Jzzhu and Sequences(矩阵加速)

    CF450B Jzzhu and Sequences 大佬留言:这.这.不就是矩乘的模板吗,切掉它!! You are given xx and yy , please calculate $f_{n ...

  6. CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂

    题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...

  7. codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)

    题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...

  8. Codeforces450 B. Jzzhu and Sequences

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. 数学 找规律 Jzzhu and Sequences

    A - Jzzhu and Sequences   Jzzhu has invented a kind of sequences, they meet the following property: ...

随机推荐

  1. DockManager 如何快速隐藏DockPanel z

    DockPanel在点击hide按钮时候如果鼠标不离开的话,panel还是没隐藏,某种情况下这种现象着实让人不爽,而且当鼠标离开后默认是很缓慢的隐藏 AutoHideSpeed不设置也可以,主要设置H ...

  2. Git 学习(三)本地仓库操作——git add & commit

    Git 学习(三)本地仓库操作——git add & commit Git 和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念.这在上文已有提及,本文具体说明什么是工作区及暂存区,以及 ...

  3. Servlet字符编码过滤器

    在Java Web程序开发中,由于Web容器内部使用编码格式并不支持中文字符集,所以,处理浏览器请求中的中文数据就会出现乱码的现象.由于Web容器使用了ISO-8859-1的编码格式,所以在Web应用 ...

  4. win C/C++程序通过Get方式获取网页源代码

    [转自]http://www.cnblogs.com/coderzh/archive/2008/11/24/1340134.html #include <stdio.h> #include ...

  5. go语言之进阶篇非结构体匿名字段

    1.非结构体匿名字段 示例 : package main import "fmt" type mystr string //自定义类型,给一个类型改名 type Person st ...

  6. 依赖注入 DI 控制反转 IOC MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. 关于html5获取用户地理位置

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title> ...

  8. 深入理解JSON

    一.JS判断字符串是否为JSON的方法: function isJSON(str) { if (typeof str == 'string') { try { JSON.parse(str); ret ...

  9. 解决duilib使用zip换肤卡顿的问题(附将资源集成到程序中的操作方法)

    转载请说明原出处,谢谢~~ 今天在做单子是.客户要求做换肤功能,为此我专门写了一个换肤函数,而且把各种皮肤资源压缩为各个zip文件来换肤.可是客户反映程序执行缓慢,我測试后发现的确明显能够看出慢了不少 ...

  10. Android -- 重置Bitmap大小&&Bitmap转角度

    重置Bitmap大小                                                                           Bitmap bitMap = ...