hdu 4565 So Easy!
来源:互联网 发布:cerber 勒索软件 编辑:程序博客网 时间:2024/05/15 05:45
点击打开hdu 4565
思路: 递推+矩阵快速幂
分析:
1 这一题和hdu 2256
几乎就是一模一样的题目,只是这边要求的是向上取整
那么我们按照hdu2256的思路来做即可点击打开hdu 2256
代码:
/************************************************ * By: chenguolin * * Date: 2013-08-28 * * Address: http://blog.csdn.net/chenguolinblog * ************************************************/#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long int64;const int N = 2; int a , b , n , MOD;struct Matrix{ int64 mat[N][N]; Matrix operator*(const Matrix& m)const{ Matrix tmp; for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j < N ; j++){ tmp.mat[i][j] = 0; for(int k = 0 ; k < N ; k++) tmp.mat[i][j] += mat[i][k]*m.mat[k][j]%MOD; tmp.mat[i][j] %= MOD; } } return tmp; }};int Pow(Matrix &m){ if(n == 1){ int x = sqrt(b); int ans = a+x; if(x*x != b) ans++; return ans%MOD; } Matrix ans; memset(ans.mat , 0 , sizeof(ans.mat)); for(int i = 0 ; i < N ; i++) ans.mat[i][i] = 1; n--; while(n){ if(n&1) ans = ans*m; n >>= 1; m = m*m; } int64 sum = 0; sum += ans.mat[0][0]*a%MOD; sum += ans.mat[0][1]%MOD; return 2*sum%MOD;}int main(){ Matrix m; while(scanf("%d" , &a) != EOF){ scanf("%d%d%d" , &b , &n , &MOD); m.mat[0][0] = m.mat[1][1] = a; m.mat[0][1] = b ; m.mat[1][0] = 1; printf("%d\n" , Pow(m)); } return 0; }
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- hdu 4565So Easy!
- hdu 4565 So Easy!
- HDU 4565 So Easy!
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- HDU 4565 SO easy!
- HDU 4565 So Easy!
- hdu 4565 So Easy!
- HDU 4565 So Easy!
- HDU 4565 So Easy!
- window 命令 生成服务
- 给oracle 增加用户 授予权限
- Java开发平台中使用Opencv如何配置?
- 黑马程序员----------高新技术JDK新特性
- eclipse打开出现JVM terminated.Exit Code=-1错误的解决办法
- hdu 4565 So Easy!
- js prototype原型面向对象编程详解GOOD
- 粘贴勿
- Ansi和Unicode字符串区别
- hdu/hdoj 1054 Strategic Game
- android自定义menu,PopUpWindow弹出菜单
- HDU:1561 The more,The Better
- 像计算机科学家一样思考python2 笔记 - 文件和模块
- IOS学习之路十九(JSON与Arrays 或者 Dictionaries相互转换)