Codeforces Round #257 (Div. 2) 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).

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

详见代码。。。

#include<iostream>
using namespace std;
#define  modulo 1000000007
int main()
{
  __int64 q[6];
  int m,n;
	  int k;
  while(~scanf("%d%d",&m,&n))
  {
     q[1]=m;
	 q[2]=n;
	 q[3]=n-m;
	 q[4]=-m;
	 q[5]=-n;
	 q[0]=m-n;
	 cin>>k;
	 k=k%6;
	 while(q[k]<0)
		 q[k]=q[k]+modulo;

		 printf("%I64d\n",q[k]%modulo);
  }
return 0;
}
时间: 2024-11-07 18:33:46

Codeforces Round #257 (Div. 2) B Jzzhu and Sequences的相关文章

Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. 1 /* 2 | 1, -1 | | fn | 3 | 1, 0 | | fn-1 | 4 */ 5 #include <iostream> 6 #include <cstdio> 7 #include <cstring> 8 using namespace std; 9 typedef __int64 LL; 10 LL mod =

Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路的权值大于该点最短距离的显然可以删去,否则将该条边加入图中,再求最短路,记录每个点的前一个点,然后又枚举铁路,已经删去的就不用处理了,如果铁路权值大于该点最短距离又可以删去,权值相等时,该点的前一个点如果不为1,则这个点可以由其他路到达,这条铁路又可以删去. 由于本题中边比较多,最多可以有8x10^

Codeforces Round #257 (Div. 2/B)/Codeforces450B_Jzzhu and Sequences

B解题报告 算是规律题吧,,,x y z -x -y -z 注意的是如果数是小于0,要先对负数求模再加模再求模,不能直接加mod,可能还是负数 给我的戳代码跪了,,, #include <iostream> #include <cstring> #include <cstdio> using namespace std; long long x,y,z; long long n; int main() { cin>>x>>y; cin>&g

Codeforces Round #258 (Div. 2) B. Jzzhu and Sequences(矩阵快速幂)

题目链接:http://codeforces.com/problemset/problem/450/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

题目链接:http://codeforces.com/problemset/problem/450/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #257 (Div. 2)449A - Jzzhu and Chocolate(贪心、数学)

题目链接:http://codeforces.com/problemset/problem/449/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943

Codeforces Round #257 (Div. 1) D - Jzzhu and Numbers 容斥原理 + SOS dp

D - Jzzhu and Numbers 这个容斥没想出来... 我好菜啊.. f[ S ] 表示若干个数 & 的值 & S == S得 方案数, 然后用这个去容斥. 求f[ S ] 需要用SOSdp #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define

Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟

E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities【最短路】

Codeforces Round #257 div.2 D or 450D Jzzhu and Cities[最短路] 题目链接:点击打开 题目大意: 在一个国家中有n个城市(城市编号1~n),m条公路和k条铁路,编号为1的城市为首都,为了节约,不需要的铁路需要关闭,问在保证首都到其余所有城市的最短路不变的条件下,最多有多少条铁路是不需要的. 解法: 这个题比较麻烦,保证首都到其余城市的最短路不变,要求出最多有多少条铁路是不需要的,那肯定是从最短路的代码上下手了,我们首先考虑dijkstra算法