codeforces-DIV2-B- Jzzhu and Sequences
来源:互联网 发布:淘宝改销量技术 编辑:程序博客网 时间:2024/06/05 02:18
Jzzhu and Sequences
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).
InputThe first line contains two integers x and y (|x|, |y| ≤ 109). The second line contains a single integer n (1 ≤ n ≤ 2·109).
OutputOutput a single integer representing fn modulo 1000000007 (109 + 7).
Sample test(s)input
2 3
3
output
1
input
0 -1
2
output
1000000006
NoteIn the first sample, f2 = f1 + f3, 3 = 2 + f3, f3 = 1.
In the second sample, f2 = - 1; - 1 modulo (109 + 7) equals (109 + 6).
斐波那契数列+负数取余+找规律
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int main(){ int i,j,n,m,f1,f2,f3; scanf("%d %d",&f1,&f2); scanf("%d",&n); if(n<3) { if(n==1) { if(f1<0) printf("%d\n",f1+1000000007); else printf("%d\n",f1%1000000007); } else { if(f2<0) printf("%d\n",f2+1000000007); else printf("%d\n",f2%1000000007); } } else { n=(n-3)%6+3; for(j=3;j<=n;j++) { f3=(f2-f1); if(f2<0) { f2=f2+1000000007; } else f2=f2%1000000007; f1=f2; if(f3<0) { f3=f3+1000000007; } else f3=f3%1000000007; f2=f3; } printf("%d\n",f3%1000000007); } return 0;}
0 0
- codeforces-DIV2-B- Jzzhu and Sequences
- Codeforces #257 div2 B. Jzzhu and Sequences
- codeforces B. Jzzhu and Sequences
- Codeforces 450 B. Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CodeForces 450-B. Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces-450B Jzzhu and Sequences
- codeforces 450B Jzzhu and Sequences
- CodeForces 450B Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CodeForces 450B-Jzzhu and Sequences
- Codeforces 450B Jzzhu and Sequences
- CF 257DIV2 B. Jzzhu and Sequences (取余需注意!!!!!!!)
- Jzzhu and Sequences CodeForces
- Jzzhu and Sequences CodeForces
- Jzzhu and Sequences CodeForces
- DIV+CSS两种盒子模型
- 2-13. 两个有序序列的中位数(25)
- 转:ubuntu命令行模式和图形界面切换
- 互联网 励志
- 2014年7月19日 22:58:57计划
- codeforces-DIV2-B- Jzzhu and Sequences
- Jthread1.3.1 Jrtplib3.9.1跨平台交叉编译之Android(一)
- 目前比较全面的浏览器CSS BUG兼容汇总
- 逻辑电门分析应用
- badblocks 检查硬盘是否有坏道
- APK ubuntu下 数字签名
- 自己动手实现一个C++智能指针
- 程序员 的出路
- [SQL_1]SQL Server 全部函数