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
 
 
 
 

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int mod=; struct Matrix{
int arr[][];
}; Matrix unit,init; Matrix Mul(Matrix a,Matrix b){
Matrix c;
for(int i=;i<;i++)
for(int j=;j<;j++){
c.arr[i][j]=;
for(int k=;k<;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&){
b=Mul(b,a);
}
a=Mul(a,a);
k>>=;
}
return b;
} void Init(){
unit.arr[][]=, unit.arr[][]=, unit.arr[][]=unit.arr[][]=; init.arr[][]=init.arr[][]=, init.arr[][]=, init.arr[][]=;
} 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-);
int ans=(*res.arr[][]-)%mod; //注意这里,刚开始这里没有%mod,WA了好几次
printf("%d\n",ans);
}
return ;
}

HDU 2256 Problem of Precision (矩阵乘法)的更多相关文章

  1. HDU 2256 Problem of Precision(矩阵)

    Problem of Precision [题目链接]Problem of Precision [题目类型]矩阵 &题解: 参考:点这里 这题做的好玄啊,最后要添加一项,之后约等于,但是有do ...

  2. HDU 2256 Problem of Precision(矩阵高速幂)

    题目地址:HDU 2256 思路: (sqrt(2)+sqrt(3))^2*n=(5+2*sqrt(6))^n; 这时要注意到(5+2*sqrt(6))^n总能够表示成an+bn*sqrt(6); a ...

  3. HDU 2256 Problem of Precision (矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 最重要的是构建递推式,下面的图是盗来的.貌似这种叫共轭数. #include <iostr ...

  4. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. hdu 2256 Problem of Precision

    点击打开hdu 2256 思路: 矩阵快速幂 分析: 1 题目要求的是(sqrt(2)+sqrt(3))^2n %1024向下取整的值 3 这里很多人会直接认为结果等于(an+bn*sqrt(6))% ...

  6. hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n    求解   ? 思路: , 令  , 那么 , 得: 得转移矩阵: 但是上面求出来的并 ...

  7. HDU 2256 Problem of Precision 数论矩阵快速幂

    题目要求求出(√2+√3)2n的整数部分再mod 1024. (√2+√3)2n=(5+2√6)n 如果直接计算,用double存值,当n很大的时候,精度损失会变大,无法得到想要的结果. 我们发现(5 ...

  8. HDU 2256 Problem of Precision( 矩阵快速幂 )

    链接:传送门 题意:求式子的值,并向下取整 思路: 然后使用矩阵快速幂进行求解 balabala:这道题主要是怎么将目标公式进行化简,化简到一个可以使用现有知识进行解决的一个过程!菜的扣脚...... ...

  9. HDU 5607 graph(DP+矩阵乘法)

    [题目链接] http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=663&pid=1002 [题意] 给定一个有向 ...

随机推荐

  1. 网站流量分析指标-PV/UV/PR/IP

    网站数据分析,经常会统计一个页面或者一个网站或者其他情况的PV/UV.下面简单说一下,这些量PV/UV/PR/IP. 1.PV PV(page view),即页面浏览量,或点击量.通常是衡量一个网络新 ...

  2. 掌握Sed命令

    带书签PDF版,喜欢的话,欢迎多提意见和建议,你的支持是血蝙蝠最大的前进动力! http://download.csdn.net/detail/challenge_c_plusplus/6480007 ...

  3. Android studio导入开源项目

    前几天从github上下载一个开源项目,发现他并不是以前Eclipse那种的目录结构 而是最近在用到的android studio的文件目录.从上图中我们可以看到多次出现了gradle这个单词.And ...

  4. Android -- SDcard文件读取和保存

    背景                                                                                            一些东西可以 ...

  5. 关于PHP写的投票网站之刷票终结版

    告诉大家一个坏消息,还是有刷票的行为,有图有真相: 倒数第三项是时间轴,倒数第二项是IP,倒数第一项是邮箱,你们要刷票,拦都拦不住呀呀呀呀呀呀!!!!! 看看这些时间的间隔,看看这些IP的地址,哎,再 ...

  6. CentOS 7.0 安装 ZCS 8.6.0

    简介 Zimbra的核心产品是Zimbra协作套件(Zimbra Collaboration Suite,简称ZCS).除了它的核心功能是电子邮件和日程安排服务器,当然还包括许多其它的功能,就象是下一 ...

  7. linux用户管理中两个重要的“父子”配置文件

    在Linux中主要通过用户配置文件来查看和修改用户信息,因此下面我们将介绍两个重要的用户配置文件,让你能够更好的hold住你的用户. 一:父文件/etc/passwd 1.查看配置文件/etc/pas ...

  8. idea 设置代码的颜色

  9. MYSQL 表中汉字写入或字段赋值时乱码情况排误

    -- 当改动字段值.或是直接写入时,汉字变成乱码情况 .[可注意一下数据库名,记得改动] -- 当字符顺序对汉字不兼容时,可能直接导致乱码情况发生. 最好做到库.表.字段(字符类型)排序规则是否一致 ...

  10. VM虚拟机启动报错Reason Failed to lock the file怎么办

    VMware启动报错Reason: Failed to lock the file的解决方法 症状:  启动VMware虚拟机的时候出现了Cannot open the disk '*.vmdk' o ...