Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
来源:互联网 发布:php 数组转json 编辑:程序博客网 时间:2024/06/06 10:52
B. Jzzhu and Sequences
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).
题意很简单。
题解:f[0]=x,f[1]=y,f[2]=y-x,f[3]=-x,f[4]=-y,f[5]=x-y。然后开始重复了,节点为6.这里求余1e9+7有个问题是负号,即是1e9+7加上这个数。有可能还是有点问题,懒得看了。
#include <bits/stdc++.h>using namespace std;const int M=1e9+7;__int64 f[10],n;__int64 mod(__int64 x){if (x>=0) return x % M;else return M+x;}int main(){scanf("%I64d%I64d",&f[0],&f[1]);//f[0]=mod(f[0]);//f[1]=mod(f[1]);f[2]=mod(f[1]-f[0]);f[3]=mod(0-f[0]);f[4]=mod(0-f[1]);f[5]=mod(f[0]-f[1]);scanf("%I64d",&n);printf("%d\n",mod(f[(n-1) % 6]));return 0;}
0 0
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2)1B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2)B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Round #257 (Div. 2) 450B - Jzzhu and Sequences(循环节或矩阵快速幂)
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵快速幂)
- Codeforces #257 (Div. 2) B. Jzzhu and Sequences
- Codeforces Div. 2 #257-B. Jzzhu and Sequences
- Codeforces#257 (Div. 2) B. Jzzhu and Sequences (数学
- Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences
- MFC学习笔记(4)—— 菜单
- hdu2063 二分图最大匹配
- 【水数组】#34 A. Reconnaissance 2
- 假设错误处理
- 女儿患罕见病 父亲嘴对嘴喂食500天_laogtxlaogt
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences
- 颜色表(部分颜色)
- nginx 超时机制
- Sprite kit学习
- 关于算法学习方法的讨论
- codeforces 257 div2 B
- UVa 10391 - Compound Words (字符串hash)
- 数据结构之哈希表
- 【足迹C++primer】48、函数引用操作符