HDU 3802 Ipad,IPhone
http://wutyyzchangde.blog.163.com/blog/static/172226566201132311311374/
#include <cstdio>
typedef struct{
__int64 matrix[2][2];
}Matrix;
__int64 powermod(__int64 x,__int64 n,__int64 p){
__int64 res = 1;
for(;n;n>>=1){
if(n&1)
res=(res*x)%p;
x=(x*x)%p;
}
return res;
}
Matrix multi(Matrix x,Matrix y,__int64 p){
Matrix res;
int i,j,k;
__int64 sum;
for(i=0;i<2;i++)
for(j=0;j<2;j++){
sum=0;
for(k=0;k<2;k++)sum+=(x.matrix[i][k]*y.matrix[k][j])%p;
res.matrix[i][j] = sum%p;
}
return res;
}
Matrix Mat_powermod(Matrix x,__int64 n,__int64 p){
Matrix res;
int i,j;
for(i=0;i<2;i++)
for(j=0;j<2;j++){
if(i==j)
res.matrix[i][j] = 1;
else res.matrix[i][j] = 0;
}
for(;n;n>>=1){
if(n&1)res=multi(res,x,p);
x=multi(x,x,p);
}
return res;
}
int main(){
__int64 p,T,a,b,n;
__int64 keep1,keep2,keep3;
__int64 power,result;
Matrix res;
scanf("%I64d",&T);
while(T--){
scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&p);
keep1=(powermod(a,(p-1)/2,p)+1)%p;
keep2=(powermod(b,(p-1)/2,p)+1)%p;
if(n==0)power=1;
else{
res.matrix[0][0] = 1;
res.matrix[0][1] = 1;
res.matrix[1][0] = 1;
res.matrix[1][1] = 0;
res=Mat_powermod(res,n-1,p-1);
power=(res.matrix[0][0]+res.matrix[0][1])%(p-1);
}
power+=p-1;
res.matrix[0][0]=(a+b)%p;
res.matrix[0][1]=(2*a*b)%p;
res.matrix[1][0]=2%p;
res.matrix[1][1]=(a+b)%p;
res=Mat_powermod(res,power-1,p);
keep3=(2*(((res.matrix[0][0]*(a+b))%p+(res.matrix[0][1]*2)%p)%p))%p;
result=1;
result=(result*keep1)%p;
result=(result*keep2)%p;
result=(result*keep3)%p;
printf("%I64d\n",result);
}
return 0;
}
HDU 3802 Ipad,IPhone的更多相关文章
- Ipad,IPhone(矩阵求递推项+欧拉定理)
Ipad,IPhone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 3802 矩阵快速幂 化简递推式子 加一点点二次剩余知识
求$G(a,b,n,p) = (a^{\frac {p-1}{2}}+1)(b^{\frac{p-1}{2}}+1)[(\sqrt{a} + \sqrt{b})^{2F_n} + (\sqrt{a} ...
- 判断访问浏览器客户端类型(pc,mac,ipad,iphone,android)
<script type="text/javascript"> //平台.设备和操作系统 var system = { win: false, mac: false, ...
- JS判断客户端系统 让ipad iphone 等手持设备自动跳到手机版
if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) { location.replace("http:// ...
- ipad iphone 开发的应用,加一个启动预览图片
如果你想在你的ipad,iphone应用启动是不显示黑屏幕,而是用一个图片代替的话,你只需要吧一张名为 Default.png 的图片加到项目里就行了. 很简单吧,新手们记得去这样美化下你的应用吗,很 ...
- 【HDU3802】【降幂大法+矩阵加速+特征方程】Ipad,IPhone
Problem Description In ACM_DIY, there is one master called “Lost”. As we know he is a “-2Dai”, which ...
- 100% width CSS 在 iPad / iPhone Safari 背景被截断 / 显示不全
Tips: 调试 iPad 或 iPhone 可在设置中启动调试模式,在 Mac 中的 Safari 浏览器 同样开启开发者模式后,进行联机调试.功能彪悍. 最近在做一个页面时,发现在 iPad 的 ...
- 根据浏览器内核判断是web/iOS/android/ipad/iphone 来打开不同的网站或页面
纯js,直接分享,直接使用: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVe ...
- ipad/iphone中的前端调试
需要在ipad上调试代码, 经过一番搜索(多在google搜到的), 稍微整理下 : ). 1. Settings -> Safari -> Advanced/Developer -> ...
随机推荐
- matlab GUI之 -- 绘图
1.常用属性 linestyle: 实线 - 虚线 -- 点线 : 点画线 -. marker: 加号 + 圆圈 O 星号 * 方块 S 三角形 ^ < > 五角星 P color: ...
- iOS keyChain(钥匙串)的简单使用
通常在开发中我们需要长久的保存某些值比如用户的账号密码等,对于隐私度很高的数据来说保证数据的安全性是尤为重要的.ios中的keyChain是一种很好的选择. 首先去开发者网站(https://deve ...
- fork进程函数总结
学习链接: http://blog.csdn.net/jason314/article/details/5640969 http://coolshell.cn/articles/7965.html 搜 ...
- 安装爬虫scrapy
使用easy_install安装scrapy,报错 error: Setup script exited with error: command 'gcc' failed with exit stat ...
- hdu 3498 whosyourdaddy 重复覆盖
题目链接 重复覆盖的入门题, 和精确覆盖不一样, 删除的时候只删除一行多列. #include<bits/stdc++.h> using namespace std; #define pb ...
- python 数字类型
数值类型:整型(int)-通常被称为是整型或整数,是正或负整数,不带数点.长整型(long integers)-无限大小的整数,整数最后是一个大写或者小写的L浮点型(floadting point r ...
- Naive Bayes Theorem and Application - Theorem
Naive Bayes Theorm And Application - Theorem Naive Bayes model: 1. Naive Bayes model 2. model: discr ...
- linux 定时执行任务
测试可以了,做个笔记 系统是centos 6.3 1,直接命令 crontab -e 编辑文件,里面写时间和你想要执行的命令. 例子 */1 * * * * sh /home/guanliyang/t ...
- Http请求 post get
package com.sprucetec.tms.utils; import org.slf4j.Logger;import org.slf4j.LoggerFactory; import java ...
- 关于oracle spfile配置文件问题
$ORACLE_SID决定spfile dbs 默认 在启动Oracle数据库时报错,如下: [oracle@localhost ~]$ sqlplus / as sysdba SQL*Plus: R ...