HDU 3292
快速幂模+佩尔方程
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
const int Mod=8191;
struct Matrax {
int m[3][3];
};
Matrax a,per; void slove(int d,int &x1,int &y1){
y1=1;
while(true){
x1=(int)sqrt(1.0*d*y1*y1+1);
if(x1*x1-d*y1*y1==1)
break;
y1++;
}
} Matrax multi(Matrax a,Matrax b){
Matrax c;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
c.m[i][j]=0;
for(int k=0;k<2;k++)
c.m[i][j]=(c.m[i][j]+a.m[i][k]*b.m[k][j])%Mod;
}
}
return c;
} Matrax Power(int k){
Matrax ans=per,p=a;
while(k){
if(k&1){
ans=multi(ans,p);
}
k>>=1;
p=multi(p,p);
}
return ans;
} int main(){
int n,k,x1,y1,xt,yt,xn,yn;
while(scanf("%d%d",&n,&k)!=EOF){
int sq=(int)sqrt(n*1.0);
if(sq*sq==n){
printf("No answers can meet such conditions\n");
continue;
}
slove(n,x1,y1);
per.m[0][0]=per.m[1][1]=1;
per.m[0][1]=per.m[1][0]=0;
a.m[0][0]=x1; a.m[0][1]=n*y1;
a.m[1][0]=y1; a.m[1][1]=x1;
Matrax ans=Power(k-1);
int ansx=0;
ansx=(ans.m[0][0]*x1+ans.m[0][1]*y1)%Mod;
printf("%d\n",ansx);
}
return 0;
}
HDU 3292的更多相关文章
- HDU 3292 【佩尔方程求解 && 矩阵快速幂】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...
- No more tricks, Mr Nanguo HDU - 3292(pell + 矩阵快速幂)
No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Jav ...
- hdu 3292 No more tricks, Mr Nanguo
No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Jav ...
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- hdoj--3635--Dragon Balls(并查集记录深度)
Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- SimpleMappingExceptionResolver异常映射
转自:https://blog.csdn.net/qqqqqq654/article/details/65767701 SimpleMappingException异常映射 当异常发生时,我们可以将它 ...
- [xPlugin] smartupload jsp图片上传
URL:http://www.cnblogs.com/ISeeYouBlogs/p/jsp.html 1.要实现图片上传,首先需要一个组件,这里我用的是smartupload.jar可以到这里下载ht ...
- iOS怎么判断字典中存在nil值
遍历字典中的key,然后根据key值取出对应的value如:for (NSString *key in dict) { //处理字典的键值 NSString *value = dict[key]; i ...
- React+webpack
webPack + React 步骤: 1. 创建文件夹 src 源代码目录 main.js 打包的入口文件 App.js 项目的根组件 import React,{Component} from ' ...
- hdu1853 Cyclic Tour 完美匹配 验证模版
题意: 给出n个城市和m条路,每个城市只能经过一次,想要旅游所有的城市,求需要的最小花费(路径的长度). 分析: 做题之前,首先要知道什么是完美匹配.不然题目做了却不知道为什么可以用这个方法来做.完美 ...
- 在YII2中使用memcached
一.在本地安装Memcached服务器和安装memcached扩展 http://www.cnblogs.com/songziqing/p/5896742.html http://www.cnblog ...
- 【Oracle】DBMS_STATS.GATHER_TABLE_STATS分析表
表分析,简单的说,就是收集表和索引的信息,CBO根据这些信息决定SQL最佳的执行路径.通过对表的分析,可以产生一些统计信息,通过这些信息oracle的优化程序可以进行优化. 语法: DBMS_STAT ...
- Windows Phone - 按钮/button 控件
System.Windows.Controls.Button button控件一.button控件的各种样式的展示可以通过 …… 来给控件定义公共的样式调用样式的方法:在Button控件上添加样式 ...
- epoll的实现与深入思考
提契 纸上得来终觉浅,绝知此事要躬行. 正文 前段时间写了一篇epoll的学习文章,但没有自己的心得总觉得比较肤浅,花了一些时间补充一个epoll的实例,并浅析一下过程中遇到的问题. 上epoll_s ...