B. Jzzhu and Sequences
来源:互联网 发布:windows 7 位置不可用 编辑:程序博客网 时间:2024/05/17 09:35
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputJzzhu 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 33
output
1
input
0 -12
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).
解题说明:此题是一个数列求值,很显然用暴力计算超时,所以需要通过找规律来缩短时间。试验过后能发现数列的周期为6,这样题目就很容易了。
#include<iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<cstdlib>#include<cstring>using namespace std;int F[10];int main() {int i, x, y, n, ans;scanf("%d %d", &x, &y);scanf("%d", &n);F[0] = x;F[1] = y;for (i = 1; i <= 6; ++i) {F[i+1] = (F[i] - F[i-1]) % 1000000007;}ans = (F[(n+5)%6] + 1000000007) % 1000000007;printf("%d\n", ans);return 0;}
0 0
- B. Jzzhu and Sequences
- B. Jzzhu and Sequences
- codeforces B. Jzzhu and Sequences
- codeforces-DIV2-B- Jzzhu and Sequences
- Codeforces 450 B. Jzzhu and Sequences
- (CF#257)B. Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CF 450B Jzzhu and Sequences
- CodeForces 450-B. Jzzhu and Sequences
- Codeforces #257 div2 B. Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces-450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CodeForces 450B-Jzzhu and Sequences
- CF 450B Jzzhu and Sequences
- mahout bayes源码分析总结
- erlang 之redis
- 最小费用最大流算法
- python海龟绘图实例教程
- 是什么感觉呢?就像自己落水了,然后在绝望的那一刻,
- B. Jzzhu and Sequences
- 上班的开始~
- 在MyEclipse8.5及以上中安装SVN插件
- linux 系统分区 和 android 分区
- 内核起步:进程管理
- Android学习路线(六)为Android应用添加ActionBar
- iOS UIView及其子类的重绘
- POJ 2115 C Looooops(扩展欧几里得应用)
- java Timer的学习笔记(一)