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 ...
随机推荐
- Linux安装和配置Vim7.4
一.简介 Vim是一个类似于Vi的文本编辑器,不过在Vi的基础上增加了很多新的特性,Vim普遍被推崇为类Vi编辑器中最好的一个,事实上真正的劲敌来自Emacs的不同变体.1999 年Emacs被选为L ...
- [Groovy] List和Map用法搜集
http://chenfeng0104.iteye.com/blog/609075 http://www.cnblogs.com/muzi1994/p/5169928.html https://zhi ...
- [SoapUI] 通过正则表达式从xml格式的response中提取ID
import com.eviware.soapui.support.GroovyUtils import java.util.regex.* //Get response def groovyUtil ...
- JavaScript的replace方法与正则表达式结合应用讲解
大家好!!今晚在华软G43*宿舍没什么事做,把javascript中replace方法讲解一下,如果讲得不对或不合理是情理之中的事,因为我不是老鸟,也不是菜鸟,我也不知道我当底是什么鸟??呵~~ re ...
- Selenium安装中的一些问题及解决办法-软硕1703班3组整理分享
非常感谢软件工程硕士1703班3组同学的热心,他们将安装Selenium过程中踩过的坑替大家填上了.希望还没有来得及踩坑的,或者掉进坑里还没爬出来的小组,能顺利跨过去这个安装的坑. 如下是原文. Se ...
- 2018.06.30 BZOJ 2342: [Shoi2011]双倍回文(manacher)
2342: [Shoi2011]双倍回文 Time Limit: 10 Sec Memory Limit: 128 MB Description Input 输入分为两行,第一行为一个整数,表示字符串 ...
- 2018.07.08 hdu1394 Minimum Inversion Number(线段树)
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- Django的路由层(2)
https://www.cnblogs.com/yuanchenqi/articles/8931472.html django2.0版的path Django默认支持以下5个转化器: str,匹配除了 ...
- 用原生的javascript 实现一个无限滚动的轮播图
说一下思路:和我上一篇博客中用JQ去写的轮播图有相同点和不同点 相同点: 首先页面布局是一样的 同样是改变.inner盒子的位置去显示不同的图片 不同点: 为了实现无限滚动需要多添加两张重复的图片 左 ...
- RESTful架构概念
本文转载自:http://www.ruanyifeng.com/blog/2011/09/restful.html 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软 ...