HDU 4565【二阶递推】
来源:互联网 发布:淘宝网logo图片 编辑:程序博客网 时间:2024/06/05 11:58
大神安利的 http://wenku.baidu.com/link?url=TQqH0Eu6SbOBNLPwIm0mECspaTw9qZ46dtGfjTepX9y_4YdR6NmtZdfSq_nFtOcaYR3_cG8WjwDqeStvgn6fUGzKKspicPOMAw-MNg15scG&qq-pf-to=pcqq.c2c
题目大意:求
怎么感觉和 JLOI2015 的那道题差不多QAQ
由条件得
先看
展开一下就知道它一定是个整数嘛
所以原式
然后就可以得到递推式
矩乘,没了…QAQ
#include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<ctime>#include<cmath>#include<string>#include<cstring>#define LL long longusing namespace std;LL n,m,a,b;LL A[2][2],t[2][2],ret[2][2];void mul(LL A[][2],LL B[][2]){ for (int i = 0;i < 2;i ++) for (int j = 0;j < 2;j ++) { t[i][j] = 0; for (int k = 0;k < 2;k ++) (t[i][j] += A[i][k] * B[k][j]) %= m; } for (int i = 0;i < 2;i ++) for (int j = 0;j < 2;j ++) A[i][j] = t[i][j];}void ksm(int B){ ret[0][0] = ret[1][1] = A[1][0] = 1; ret[0][1] = ret[1][0] = A[1][1] = 0; A[0][0] = a * 2,A[0][1] = b - a * a; for (;B;B >>= 1,mul(A,A)) if (B & 1) mul(ret,A);}LL F(int n){ int s = sqrt(b),t = (s * s != b); if (n == 1) return (a + s + t) % m; else return (a * a + b + (int)(sqrt(b) * a * 2) + t) % m;}int main(){ while (~scanf("%lld%lld%lld%lld",&a,&b,&n,&m)) { if (n == 1) { cout << F(1) << endl; continue; } ksm(n - 2); cout << ((ret[0][0] * F(2) + ret[0][1] * F(1)) % m + m) % m << endl; } return 0;}
0 0
- HDU 4565【二阶递推】
- hdu 4565
- hdu 4565
- HDU 3802 【二阶递推】
- 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 SoEasy!
- Linux3.6.7中Make uImage的load address 和 Entry Point相同的问题
- 关于java的Metrics的简单介绍
- JSONObject返回到前端转化出错
- ANDROID L - Material Design详解(视图和阴影)
- MySQL 常用函数 数学函数
- HDU 4565【二阶递推】
- Xshell秘钥登录Linux服务器: root && 普通用户
- Gallery
- MySQL5.6免安装版的安装教材教程
- hdu3001(状态压缩dp)
- SQLite3 API 学习
- h5设计稿尺寸详解
- CyberLink YouCam 新人求教一个绿色背景提取红色小球的问题
- C# 汉字转拼音(支持GB2312字符集中所有汉字)