广东女子职业技术学院论坛

 找回密码
 注册
搜索
查看: 37799|回复: 3
打印 上一主题 下一主题

辛有才网络营销-2015沈阳网络赛 1002(HDU 5451 矩阵快速幂 + 矩阵循环群)

[复制链接]
跳转到指定楼层
#楼
发表于 2015-12-29 03:50:31 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
HDU 5451 题意:  
  输入 x ( 0 > t ; int kase = 1 ; while( t-- )#define out( kase ) printf( "Case #%d: " , kase++ )#define mp make_pair#define pb push_backtypedef long long lint;typedef long long ll;typedef long long LL;int mod ;const int maxn = 4;struct Matrix{ int n,m; lint a[maxn][maxn]; Matrix(int n , int m){ this->n = n; this->m = m; cls(a); } Matrix operator * (const Matrix &tmp){ Matrix res(n,tmp.m); for(int i = 0 ; i >= 1; } return res;}lint quick_pow( lint x , lint n , lint p ){ lint res = 1 ; x %= p ; while( n ){ if( n & 1 ) res = res * x % p ; n >>= 1 ; x = x * x % p ; } return res ;}void solve(){ lint n , x; cin >> x >> mod ; lint MOD = ( mod - 1 ) * ( mod + 1 ) ; n = quick_pow( 2 , x , MOD ) + 1 ; if( n == 0 ){ cout << 1 << endl ; return ; } if(n == 1){ cout << 9 << endl; return; } Matrix base(2,1); Matrix fun(2,2); base.a[0][0] = 5; base.a[1][0] = 2; fun.a[0][0] = 5; fun.a[0][1] = 12; fun.a[1][0] = 2; fun.a[1][1] = 5; fun = fast_pow(fun,n-1); base = fun * base; cout << (2*base.a[0][0] - 1) % mod << endl;}int main(){ //freopen( "input.txt" , "r" , stdin ) ; test( t ){ out( kase ) ; solve(); } return 0;}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机访问本页请
扫描左边二维码
         本网站声明
本网站所有内容为网友上传,若存在版权问题或是相关责任请联系站长!
站长联系QQ:7123767   myubbs.com
         站长微信:7123767
请扫描右边二维码
www.myubbs.com

小黑屋|手机版|Archiver|广东女子职业技术学院论坛 ( 琼ICP备12002442号 )

GMT+8, 2024-4-26 07:50 , Processed in 0.044707 second(s), 14 queries .

Powered by 高考信息网 X3.3

© 2001-2013 大学排名

快速回复 返回顶部 返回列表