codeforces 450 B Jzzhu and Sequences
题意:给出f1=x,f2=y,f(i)=f(i-1)+f(i+1),求f(n)模上10e9+7
因为 可以求出通项公式:f(i)=f(i-1)-f(i-2)
然后
f1=x;
f2=y;
f3=y-x;
f4=-x;
f5=-y;
f6=-y+x;
f7=x; 发现是以6为循环的
还有注意下余数为正,就每次加上一个mod再模上mod
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; LL a[]; int main(){
LL x,y,n;
cin>>x>>y;
cin>>n;
a[]=(x+mod)%mod;
a[]=(y+mod)%mod;
a[]=(y-x+*mod)%mod;
a[]=(-x+mod)%mod;
a[]=(-y+mod)%mod;
a[]=(-y+x+*mod)%mod;
cout<<a[n%]<<"\n";
return ;
}
codeforces 450 B Jzzhu and Sequences的更多相关文章
- codeforces 450B B. Jzzhu and Sequences(矩阵快速幂)
题目链接: B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input ...
- codeforces 257div2 B. Jzzhu and Sequences(细节决定一切)
题目链接:http://codeforces.com/contest/450/problem/B 解题报告:f1 = x,f2 = y,另外有当(i >= 2) fi = fi+1 + fi-1 ...
- Codeforces 450 C. Jzzhu and Chocolate
//area=(n*m)/ ((x+1)*(k-x+1)) //1: x==0; //2: x=n-1 //3: x=m-1 # include <stdio.h> long long m ...
- Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)
题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...
- CodeForces 450B Jzzhu and Sequences (矩阵优化)
CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...
- Codeforces Round #257 (Div. 2 ) B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CodeForces - 450B Jzzhu and Sequences —— 斐波那契数、矩阵快速幂
题目链接:https://vjudge.net/problem/CodeForces-450B B. Jzzhu and Sequences time limit per test 1 second ...
- CodeForces 450
A - Jzzhu and Children Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & % ...
- Codeforces450 B. Jzzhu and Sequences
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- List Comprehensions
看Python高级编程时有几个东西要记一记,方便以后查询 以下代码基本全摘自Python高级编程 取0~9之间的偶数,类C语言写法: 使用list comprehensions可以极大程度上简化语法: ...
- 采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展
原文:http://www.cnblogs.com/sanshi/archive/2012/06/22/2558476.html 若是持久Cookie,Cookie的有效期Expiration属性有当 ...
- HDU5002 Tree(LCT)
今天做了一道LCT模板题之后忽然间好像记起来LCT的模板怎么用了,于是就把上次网络赛的一道LCT补一下.典型的删边,加边操作,还有路径加和路径set为一个数.维护的是路径第二大以及它有多少个,后来想想 ...
- Android ListVIew 详解(一)
在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根据数据的长度自适应显示.抽空把对ListView的使用做了整理,并写了个小例子,如下图. 列表的显示需要三 ...
- Shell实现跳板机,为什么用跳板机
整理自:http://blog.chinaunix.net/uid-22101889-id-3167454.html 注意:请谨慎使用,到现在为止,使用了,我还没找到改回去的方法. 1. 问题 ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- ExtJs之addManagedListener
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- Java集合框架(三)
Map Map集合:该集合存储键值对,一对一对的往里存,而且要保证键的唯一性. Map |------HashTable:底层是哈希表数据结构,不可以存入null键null值.该集合是线程同步的.J ...
- Log4net学习
转自:http://www.cnblogs.com/sirkevin/archive/2012/06/13/2548449.html Log4net简介根据日志类别保存到不同的文件,并按照日期生成不同 ...
- awk除去重复行
awk去除重复行,思路是以每一行的$0为key,创建一个hash数组,后续碰到的行,如果数组里已经有了,就不再print了,否则将其print 测试文件: 用awk: 用sort+uniq好像出错了: ...