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 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 33
output
1
input
0 -12
output
1000000006
Note

In the first sample, f2 = f1 + f33 = 2 + f3f3 = 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
原创粉丝点击