题目链接:https://vjudge.net/problem/CodeForces-450B

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

Example

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

解题思路:

  由数学公式f2 = f1 + f3输出任意 fn,看似简单,可是由于数据范围为2e9,所以明显是道矩阵快速幂,可是写的时候推导了前8项,发现每6个一个循环节,于是有了一种更简单的写法,具体看代码吧!

AC代码:

#include <stdio.h>
#include <math.h>
const long long MOD=1e9+;
int main()
{
int a[],n;
while(~scanf("%d %d",&a[],&a[]))
{
scanf("%d",&n);
for(int i=;i<=;i++)
a[i]=a[i-]-a[i-];
a[]=a[];
int ans;
ans=( a[n%]%MOD + MOD ) %MOD;
printf("%d\n",ans); }
return ;
}

Codeforces450 B. Jzzhu and Sequences (找规律)的更多相关文章

  1. Codeforces450 B. Jzzhu and Sequences

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

  2. 450A - Jzzhu and Children 找规律也能够模拟

    挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...

  3. Finite Encyclopedia of Integer Sequences(找规律)

    6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec  内存限制: 128 MB提交: 375  解决: 91[提交] [状态] [讨论 ...

  4. CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD

    题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...

  5. 数学 找规律 Jzzhu and Sequences

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

  6. (CF#257)B. Jzzhu and Sequences

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

  7. The Cow Lineup_找规律

    Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled ...

  8. HDU 5753 Permutation Bo (推导 or 打表找规律)

    Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...

  9. 计蒜客 39279.Swap-打表找规律 (The 2019 ACM-ICPC China Shannxi Provincial Programming Contest L.) 2019ICPC西安邀请赛现场赛重现赛

    Swap There is a sequence of numbers of length nn, and each number in the sequence is different. Ther ...

随机推荐

  1. 11月11日光棍节考试总结hhh

    好吧,第一题字符串裸栈就能A 第二题字典序没调完,先写的第一题和第三题暴力,第二题读题感觉自己不会写,其实也能写出来,浪费了好多时间 第三题DP大概是写的暴力,原本可以搞到20分,要交的时候发现自己少 ...

  2. git 提交新创建的文件

    git add -u:把所有tracked文件中被修改过或已删除文件的信息添加到索引库.它不会处理untracted的文件. 如果想将本地新创建的文件也提交上去,需执行如下操作:

  3. 使用dos 作为中介实现cpython 和c# 交互

    最近在使用python 处理一些图形的东西. 实现:对一些512 的图进行像素遍历RGBA 变量, 查询通道不是 255 255 255 颜色 的矩阵,进行切图到空白 之前使用c#进行 确实快10 倍 ...

  4. KBMMW 4.83.00 发布

    新版本又来了,端午节都不让大家过好:) 这次终于支持ios 64了,不用我再手工改了. Components4Developers is a company established in 1999 w ...

  5. 521. Longest Uncommon Subsequence I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  6. 第八章 连词(Les conjonction )

    ★并列连词(La conjonction de coordination ) ()表示联合关系的并列连词 .et连接肯定的内容.如:    ➞Il conduit vite et bien.      ...

  7. Java中读取.properties配置文件的通用类

    由于Java中读取配置文件的代码比较固定,所以可以将读取配置文件的那部分功能单独作为一个类,以后可以复用.为了能够达到复用的目的,不能由配置文件中每一个属性生成一个函数去读取,我们需要一种通用的方法读 ...

  8. 《Linux多线程服务端编程——使用muduo C++网络库》读书笔记

    第一章 线程安全的对象生命期管理 第二章 线程同步精要 第三章 多线程服务器的适用场合与常用编程模型 第四章 C++多线程系统编程精要 1.(P84)11个常用的最基本Pthreads函数: 2个:线 ...

  9. vi 基本使用命令

    说明:以下的例子中 xxx 表示在命令模式下输入 xxx 并回车以下的例子中 :xxx 表示在扩展模式下输入 xxx 并回车小括号中的命令表示相关命令在编辑模式或可视模式下输入的命令会另外注明 1 查 ...

  10. python 求第k个最大数

    #coding = utf-8 import sys def Cal_NO(a,b): nums=sorted(a,reverse=True) result=nums[b-1] return resu ...