博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kuangbin带你飞,矩阵(简单数学推导题)
阅读量:5232 次
发布时间:2019-06-14

本文共 1722 字,大约阅读时间需要 5 分钟。

A - Jzzhu and Sequences
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit 

Description

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 Input

Input
2 3 3
Output
1
Input
0 -1 2
Output
1000000006

Hint

In the first sample, f2 = f1 + f33 = 2 + f3f3 = 1.

In the second sample, f2 =  - 1;  - 1 modulo (109 + 7) equals (109 + 6).

 

题目大意:

  输入f2和f1的值,最后算出fn的值。

解题思路:

f[1] = x;f[2] = y;

f[i] = f[i-1]+f[i+1]
i = 1;
f[1] = f[0]+f[2];->f[0] = x-y;
i = 2;
f[2] = f[1]+f[3];->f[3] = y-x;
i = 3;
f[3] = f[2]+f[4];->f[4] = -x;
i = 4;
f[4] = f[3]+f[5];->f[5] = -y
i = 5;
f[5] = f[4]+f[6];->f[6] = x-y;

一开始被51组数据卡了三次,原因就是在取MOD的过程中,如果a[n]<0..while ( a[n]<0 )a[n]+=MOD;将其变为正数后,才能进行a[n]%MOD的运算。

代码:

# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;const double PI=4.0*atan(1.0);typedef long long LL;typedef unsigned long long ULL;# define inf 999999999# define MOD 1000000007LL a[10];int x,y,n;void init(){ a[0] = x-y; a[1] = x; a[2] = y; a[3] = y-x; a[4] = -x; a[5] = -y;}int main(void){ while ( cin>>x>>y ) { init(); cin>>n; n%=6; while ( a[n]<0 ) a[n]+=MOD; cout<
<
View Code

 

转载于:https://www.cnblogs.com/wikioibai/p/4392761.html

你可能感兴趣的文章
guava API整理
查看>>
无锁编程笔记
查看>>
jquery mobile
查看>>
如何在vue单页应用中使用百度地图
查看>>
Springboot使用步骤
查看>>
Spring属性注入
查看>>
Springboot-配置文件
查看>>
Springboot-日志框架
查看>>
SpringBoot-thymeleaf
查看>>
P1908-逆序对
查看>>
P1192-台阶问题
查看>>
ACM模板——康托展开
查看>>
P1025-数的划分
查看>>
P1305-新二叉树
查看>>
给网站配置免费的HTTS证书
查看>>
android 往sd卡中写入文件
查看>>
mysql主从同步配置和读写分离实现(中间件Amoeba)
查看>>
golang lua使用示例
查看>>
64位win2003/win2008系统IIS6.0/7.5配置PHP的方法
查看>>
5月深度学习班第3课梯度下降法与反向传播
查看>>