Codeforces450 B. Jzzhu and Sequences (找规律)
题目链接: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 (找规律)的更多相关文章
- Codeforces450 B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 450A - Jzzhu and Children 找规律也能够模拟
挺水的一道题.规律性非常强,在数组中找出最大的数max,用max/m计算出倍数t,然后再把数组中的书都减去t*m,之后就把数组从后遍历找出第一个大于零的即可了 #include<iostream ...
- Finite Encyclopedia of Integer Sequences(找规律)
6617: Finite Encyclopedia of Integer Sequences 时间限制: 1 Sec 内存限制: 128 MB提交: 375 解决: 91[提交] [状态] [讨论 ...
- CodeForces 450B Jzzhu and Sequences 费波纳茨数列+找规律+负数MOD
题目:Click here 题意:给定数列满足求f(n)mod(1e9+7). 分析:规律题,找规律,特别注意负数取mod. #include <iostream> #include &l ...
- 数学 找规律 Jzzhu and Sequences
A - Jzzhu and Sequences Jzzhu has invented a kind of sequences, they meet the following property: ...
- (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 ...
- The Cow Lineup_找规律
Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled ...
- HDU 5753 Permutation Bo (推导 or 打表找规律)
Permutation Bo 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5753 Description There are two sequen ...
- 计蒜客 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 ...
随机推荐
- js和jquery获取span里面的值
JQ和Js获取span标签的内容 html: 1 <span id="content">‘我是span标签的内容’</span> javascript获取: ...
- DB2锁机制
相比较Oracle来说,DB2的锁机制麻烦了很多,而且这个麻烦带来的不是性能的上升而是下降,不过如果细致了解的话,只能感慨不愧是数据库理论诞生的公司,在实现数据库理论上比Oracle全面得多. ...
- Boolean.getBoolean用法
相信很多人被Boolean.getBoolean(String name)欺骗过,想当然的认为它是将"true"或者"false"转换为Boolean类型的AP ...
- VK Cup 2016 D. Bear and Two Paths 模拟
D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- NOIP 2016 游记
- _GET_
_GET_:读取属性,没有自动创建
- jquery阻止表单提交
<form action="" method="post" onSubmit="return confirm();" > < ...
- UDP接收数据
http://blog.csdn.net/xingzheouc/article/details/49946191 http://blog.csdn.net/robertkun/article/deta ...
- HttpClient的几个实现类
DefaultHttpClient最基本的HttpClient实现 org.apache.http.impl.client.DefaultHttpClient占用内存23字节 第一次初始化的时候需要2 ...
- python的介绍和及基本的使用
一 什么是计算机 1 计算机就是由一堆硬件组成的一个机器. 2 硬件的分类: CPU:犹如人类的大脑,运行着需要运行的程序. 内存:将 CPU要运行的内容从硬盘中读取出来,然后CPU在内存里拿内容,只 ...