博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 2256 Problem of Precision (矩阵乘法)
阅读量:6894 次
发布时间:2019-06-27

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

Problem of Precision

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 686    Accepted Submission(s): 386

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
3 1 2 5
 

 

Sample Output
9 97 841
 

 

Source
 

 

Recommend
lcy
 
 
杭电 hdu 2256 Problem of Precision - fwhjyhp - ☆漫步云端☆的博客
 
 

 

 
#include
#include
#include
using namespace std;const int mod=1024;struct Matrix{ int arr[2][2];};Matrix unit,init;Matrix Mul(Matrix a,Matrix b){ Matrix c; for(int i=0;i<2;i++) for(int j=0;j<2;j++){ c.arr[i][j]=0; for(int k=0;k<2;k++) c.arr[i][j]=(c.arr[i][j]+a.arr[i][k]*b.arr[k][j]%mod)%mod; c.arr[i][j]%=mod; } return c;}Matrix Pow(Matrix a,Matrix b,int k){ while(k){ if(k&1){ b=Mul(b,a); } a=Mul(a,a); k>>=1; } return b;}void Init(){ unit.arr[0][0]=5, unit.arr[0][1]=2, unit.arr[1][0]=unit.arr[1][1]=0; init.arr[0][0]=init.arr[1][1]=5, init.arr[0][1]=2, init.arr[1][0]=12;}int main(){ //freopen("input.txt","r",stdin); int t,n; Init(); scanf("%d",&t); while(t--){ scanf("%d",&n); Matrix res=Pow(init,unit,n-1); int ans=(2*res.arr[0][0]-1)%mod; //注意这里,刚开始这里没有%mod,WA了好几次 printf("%d\n",ans); } return 0;}

 

 

转载地址:http://jmzdl.baihongyu.com/

你可能感兴趣的文章
查看死锁存储过程(转载)
查看>>
iOS:Masonry介绍与使用
查看>>
看百度宣传片
查看>>
Java assert
查看>>
Impala与HBase整合
查看>>
c# 获取某个进程的CPU使用百分百(类似任务管理器中显示CPU)
查看>>
关于__GNU_SOURCE 这个宏---如何开启【转】
查看>>
【SQL】姗姗来迟的SQL Server 安装图解
查看>>
POJ 3017 单调队列dp
查看>>
【OneNote Mobile】 如何处理便签内容的格式?
查看>>
ios开发学习-弹出视图(Popup View) 效果源码分享--系列教程1
查看>>
css中 Span 元素的 width 属性无效果原因及多种解决方案
查看>>
ABP框架理论研究总结(典藏版)
查看>>
CNNVD发布2015年信息安全漏洞态势报告
查看>>
【深度】AI 入侵翻译,神经机器翻译进化让巴别塔7年内成真
查看>>
《Ext JS权威指南》——2.10节本章小结
查看>>
思科发布新系列智能协作终端产品
查看>>
脑芯编:窥脑究竟,织网造芯(一)
查看>>
《React Native移动开发实战》一一1.1 看透React Native
查看>>
大数据如何解决行业挑战?大数据在10个垂直行业中的应用
查看>>