【矩阵快速幂-求平方根表达式的值】HDU Problem of Precision 2256
来源:互联网 发布:买家如何申请淘宝介入 编辑:程序博客网 时间:2024/05/17 02:09
Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1055 Accepted Submission(s): 622
Problem Description
Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n. (1 <= n <= 10^9)
Output
For each input case, you should output the answer in one line.
Sample Input
3125
Sample Output
997841
Source
HDOJ 2008 Summer Exercise(4)- Buffet Dinner
题意:
简单明了。不再解释。
解题思路:
盗图。。这图讲的足够了。
矩阵:
AC代码:
#include <stdio.h>#include <string.h>#include <algorithm>#define MOD 1024using namespace std;typedef int LL;LL Mat[2][2];LL res[2][2];void init(){ for(int i=0;i<2;i++){ for(int j=0;j<2;j++){ res[i][j]=(i==j); } } Mat[0][0]=5;Mat[0][1]=2; Mat[1][0]=12;Mat[1][1]=5;}void Matmul(LL a[2][2],LL b[2][2]){ LL t[2][2]={0}; for(int i=0;i<2;i++){ for(int k=0;k<2;k++){ if(a[i][k]){ for(int j=0;j<2;j++){ t[i][j]=(t[i][j]+a[i][k]*b[k][j]%MOD)%MOD; } } } } for(int i=0;i<2;i++) for(int j=0;j<2;j++) a[i][j]=t[i][j];}void Matrix(LL x[2][2],LL n){ while(n){ if(n&1) Matmul(res,x); Matmul(x,x); n>>=1; }}int main(){ int t; scanf("%d",&t); while(t--){ LL n; scanf("%d",&n); init(); Matrix(Mat,n-1); LL ans[2]; LL cnt=0; ans[0]=5;ans[1]=2; for(int i=0;i<2;i++){ cnt=(cnt+ans[i]*res[i][0]%MOD)%MOD; } printf("%d\n",(2*cnt-1)%MOD); } return 0;}
Problem of Precision
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1055 Accepted Submission(s): 622
Problem Description
Input
The first line of input gives the number of cases, T. T test cases follow, each on a separate line. Each test case contains one positive integer n. (1 <= n <= 10^9)
Output
For each input case, you should output the answer in one line.
Sample Input
3125
Sample Output
997841
Source
HDOJ 2008 Summer Exercise(4)- Buffet Dinner
0 0
- 【矩阵快速幂-求平方根表达式的值】HDU Problem of Precision 2256
- HDU 2256 Problem of Precision (矩阵快速幂)
- Hdu 2256 Problem of Precision[矩阵快速幂 + 数学]
- HDU 2256 Problem of Precision(矩阵快速幂)
- hdu 2256 Problem of Precision(矩阵快速幂 推公式)
- HDU - 2256 Problem of Precision 矩阵快速幂
- hdu 2256 Problem of Precision 矩阵快速幂
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU 2256 Problem of Precision(矩阵快速幂 数论 )
- HDU 2256 Problem of Precision(矩阵快速幂)
- HDU.2256 Problem of Precision (矩阵快速幂)
- Problem of Precision(矩阵快速幂)
- [矩阵快速幂]hdu2256 Problem of Precision
- hdu 2256 Problem of Precision(矩阵快速幂,得出递推式有难度)
- HDU 2256 Problem of Precision 解题报告(矩阵快速幂 + 构造)
- HDU 2256 Problem of Precision(矩阵快速幂入门题)
- HDU 2256 Problem of Precision (矩阵快速幂+ 化简 +向下取整)
- hdu 2256 Problem of Precision 矩阵
- TCP和UDP之间的区别
- 黑马程序员—进制、数组和字符串
- Math类
- Xcode 7 iTunesconnect 上传时遇到问题
- 【转】关于 float、position学习心得
- 【矩阵快速幂-求平方根表达式的值】HDU Problem of Precision 2256
- 可能导致Java内存泄漏的几项原因
- 使用java编写的冒泡排序小程序
- Mysql笔记:体系结构
- 丑数
- MacBook Pro 桌面与屏幕保护程序出现假死
- andriod开发点滴(使用真机调试)
- 一个刚踏入算法之路的小生
- 阶乘因式分解:求阶乘后某因子个数