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 ...
随机推荐
- final修饰符:
知识点: 1.final关键字用于修饰类.变量和方法 2.有点类似C#里的 sealed 关键字,用于表示它修饰的方法.变量和类不可以再被改变 3.final修饰变量时,表示该变量一旦获取了初始值,就 ...
- Java的8种包装类:Wrapper Class
Java有8种基本数据类型,为什么又要出现对应的8种包装类: 1.Java的8种基本数据类型不支持面向对象编程机制 2.8种基本数据类型不具备“对象”的特性:没有成员变量.方法可供调用 3.例如:某个 ...
- /^\s+|\s+$/g 技术 内容
alert(" aa dd ".replace(/^\s+|\s+$/g,'')+"方式的"); //正则表达式解释:分成两部分,^\s+ 以空格开头,\s+$ ...
- mac windows蓝牙问题
如果是win7.win8或win10三者的64位版本,可以下载驱动解决:http://file2.mydrivers.com/2014/notebook/apple_broadcom_bluetoot ...
- n&&m and n||m 的区别
今天写一道题老是WA最后才发现问题出在了这个地方, 题目说的是当输入的n和m 都为0的时候,结束输入. 于是乎,条件我就写成了while(n&&m),其实这句话的意思是:只有m和n都不 ...
- WinRT 中后台任务类的声明
要实现后台任务,需要实现IBackgroundTask接口 public sealed class SimpleTask : IBackgroundTask { public void Run(IBa ...
- Elasticsearch 在 windows 和 ubuntu 下详细安装过程
1. 前言 作为一名 .NET 平台开发者,选择开发框架时总会面临更多的局限性,不过对于搜索这种刚需服务来说,开源框架可供选择的余地还是比较大的.笔者之前用的是 Lucene.net ,现在深感其使用 ...
- DAC--使用DAC来导出数据库脚本
//============================================== //功能介绍:使用DAC来导出数据库脚本 //注意事项: //1.本程序涉及到的DLL有: // - ...
- Create Index语句的Include作用
在 SQL Server 2005 中,可以通过将非键列添加到非聚集索引的叶级别来扩展非聚集索引的功能.通过包含非键列,可以创建覆盖更多查询的非聚集索引.这是因为非键列具有下列优点: 它们可以是不允许 ...
- 利用HttpWebRequest模拟表单提交
using System; using System.Collections.Specialized; using System.IO; using System.Net; using System. ...