HDU 3292 (佩尔方程 矩阵快速幂)
来源:互联网 发布:blued交友软件 编辑:程序博客网 时间:2024/05/18 03:35
题目链接:点击这里
题意:求解佩尔方程
首先暴力求出佩尔方程的最小特解,然后根据迭代式子
直接用矩阵快速幂求出结果即可。
#include <bits/stdc++.h>using namespace std;#define maxn 500005#define INF 1e15#define mod 8191struct m { long long a[2][2]; m operator * (const m &gg) const { m ans; memset (ans.a, 0, sizeof ans.a); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { for (int l = 0; l < 2; l++) { ans.a[i][j] += a[i][l]*gg.a[l][j]; ans.a[i][j] %= mod; } } } return ans; } void show () { for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) cout << a[i][j] << " "; cout << endl; } }};m qpow (m a, long long kk) { m ans; int i, j; for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) ans.a[i][j] = (i == j ? 1 : 0); for(; kk; kk >>= 1) { if(kk&1) ans = ans*a; a = a*a; } return ans;}int n, k;void solve (long long x, long long y, long long k) { m ans; ans.a[0][0] = x, ans.a[0][1] = n*y; ans.a[1][0] = y, ans.a[1][1] = x; ans = qpow (ans, k-1); cout << (x*ans.a[0][0]+y*ans.a[0][1]) % mod << endl;}int main () { while (cin >> n >> k) { if (n == 1 || n == 4 || n == 9 || n == 16 || n == 25) { cout << "No answers can meet such conditions" << endl; continue; } for (long long y = 1; ; y++) { long long x = sqrt (1LL*n*y*y+1); if (x*x-y*y*n == 1) { //cout << x << " " << y << endl; solve (x, y, k); goto out; } } //cout << "No answers can meet such conditions" << endl; out: ; } return 0;}
0 0
- HDU 3292 佩尔方程+矩阵快速幂
- HDU 3292 (佩尔方程 矩阵快速幂)
- HDU 3292 No more tricks, Mr Nanguo(佩尔方程,矩阵快速幂)
- HDU 3292(No more tricks, Mr Nanguo 佩尔方程矩阵快速幂求解)
- hdu 3292 No more tricks, Mr Nanguo pell方程+矩阵快速幂
- c语言版 佩尔方程求最小正整数解及第k解(矩阵快速幂)
- hdu3802 矩阵快速幂&特征方程&降幂
- 矩阵快速幂+高斯消元解递推方程-HDU6185
- HDU 3292 No more tricks, Mr Nanguo 矩阵快速幂求佩尔方程第k大的解
- hdu 3292 No more tricks, Mr Nanguo(矩阵快速幂解佩尔方程)
- HDU 3292 No more tricks, Mr Nanguo [佩尔方程+矩阵]【数论】
- hdu 3292 佩尔方程一系列操作
- 【矩阵快速幂+递推方程】The Little Architect
- 差分方程求解,leslie矩阵的快速幂。
- 【矩阵快速幂】hdu 1575
- 【矩阵快速幂】hdu 1757
- hdu 2604 矩阵快速幂
- hdu-1575矩阵快速幂
- 安装配置Tomcat
- ${pageContext.request.contextPath} JSP取得绝对路径(学习)
- Adobe Media Server 5(AMS)的简单配置
- iOS10 调用系统相机拍照后黑屏的问题
- 单例模式
- HDU 3292 (佩尔方程 矩阵快速幂)
- tomcat服务重启后是session失效的方法
- 一些稀有的博客连接和知识点
- app中webview显示网页,类似于微信里点击链接
- NEON下函数详解-------vcvt_f32_s32
- WinFrom窗体始终置顶
- JAVA程序操作hbase的Maven配置
- iOS 生成二维码
- gensim的word2vector测试_基于中文wiki语料