HDU 4291 A Short problem (2012成都网络赛,矩阵快速幂+循环节)
来源:互联网 发布:知柏地黄丸与难入睡 编辑:程序博客网 时间:2024/04/30 09:16
链接: click here~~
题意:
According to a research, VIM users tend to have shorter fingers, compared with Emacs users.
Hence they prefer problems short, too. Here is a short one:
Given n (1 <= n <= 1018), You should solve for
where
Input
There are several test cases. For each test case there is an integer n in a single line.
Please process until EOF (End Of File).
Please process until EOF (End Of File).
Output
For each test case, please print a single line with a integer, the corresponding answer to this case.
Sample Input
012
Sample Output
0142837
代码:
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <math.h>using namespace std;#define LL long longconst long long mod1=1e9+7;const long long mod2=222222224;const long long mod3=183120;struct Matrix{ long long mapp[2][2];};Matrix p= {0,1,1,0};Matrix p1= {0,1,1,3};Matrix unin= {1,0,0,1};Matrix powmul(Matrix a,Matrix b,long long mod){ Matrix c; for(int i=0; i<2; i++) for(int j=0; j<2; j++) { c.mapp[i][j]=0; for(int k=0; k<2; k++) c.mapp[i][j]+=(a.mapp[i][k]*b.mapp[k][j])%mod; c.mapp[i][j]%=mod; } return c;}Matrix powexp(long long n,long long mod){ Matrix m=p1,b=unin; while(n>=1) { if(n&1) b=powmul(b,m,mod); n>>=1; m=powmul(m,m,mod); } return powmul(p,b,mod);}long long T;int main(){ while(~scanf("%lld",&T)) { Matrix ans; ans=powexp(T,mod3); ans=powexp(ans.mapp[0][0],mod2); ans=powexp(ans.mapp[0][0],mod1); cout<<ans.mapp[0][0]<<endl; // printf("%lld\n",ans.mapp[0][0]); } return 0;}
0 0
- HDU 4291 A Short problem (2012成都网络赛,矩阵快速幂+循环节)
- hdu4291 A Short problem 矩阵快速幂 求循环节----成都网络赛
- HDU 4291 A Short problem(矩阵快速幂+循环节)
- HDU 4291 A Short problem // 矩阵快速幂, 循环节
- HDU 4291-A Short problem-循环节+矩阵快速幂
- HDU 4291 A Short problem(矩阵快速幂取模求循环节)
- HDU 4291:A Short problem_成都赛区网络赛—矩阵快速幂
- HDU 4291 A Short problem(矩阵快速幂+循环节)
- HDU——4291A Short problem(矩阵快速幂+循环节)
- hdu 4291 A Short problem 矩阵快速幂,找循环节
- HDU-4291 A Short problem(矩阵快速幂)
- hdu 4291 A Short problem(矩阵快速幂)
- hdu 4291 (循环节+矩阵快速幂,2012成都网络选拔赛1004)
- hdu 4291 A Short problem 矩阵+循环
- 【HDU】4291 A Short problem 矩阵快速幂
- hdu 4291 A Short problem 打表找规律&矩阵快速幂
- hdu 4291 A Short problem(矩阵快速幂)
- hdoj 4291 A Short problem 【找循环节 + 矩阵快速幂】
- 一个程序员对李开复自传的记忆----未完待续
- 常用的正则表达式大全
- 代码管理Git-建立 Remote Branch 的相關指令操作
- easyui datagrid无数据时显示横向滚动条
- android--布局组件截图
- HDU 4291 A Short problem (2012成都网络赛,矩阵快速幂+循环节)
- Java基础和语句结构
- 使用Supervisord实现Docker Container的自启动
- IPC(Inter Process Connection) 总结笔记(1)
- 【oracle】分区表:range分区,list分区,hash分区
- JAVA IO: Java RandomAccessFile用法
- 第11课时,实践3,如何买玫瑰?
- Yarn常用命令
- NBU对Oracle备份及恢复手册