HDU 2281 Square Number Pell方程
http://acm.hdu.edu.cn/showproblem.php?pid=2281
又是一道Pell方程
化简构造以后的Pell方程为

求出其前15个解,但这些解不一定满足等式,判断后只有5个满足的情况,直接判断即可
求法可以参照上一篇日志: http://www.cnblogs.com/Felix-F/p/3223323.html
struct matrix
{
LL ma[][];
};
int n = ;
LL nn[],xx[];
matrix operator * (matrix a,matrix b)
{
matrix temp;
memset(temp.ma,,sizeof(temp.ma));
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
for(int k = ; k < n ; k++)
temp.ma[i][j] = temp.ma[i][j] + (a.ma[k][i] * b.ma[j][n-k-]);
return temp;
}
matrix operator + (matrix a,matrix b)
{
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
a.ma[i][j] = (a.ma[i][j] + b.ma[i][j]) ;
return a;
}
void init()
{
matrix a;
a.ma[][] = ;
a.ma[][] = ;
a.ma[][] = ;
a.ma[][] = ;
matrix temp = a;
nn[] = ;
xx[] = ;
int cnt = ;
for(int i = ;i <= ; i++)
{
if(i% == )
{
LL s1 = temp.ma[][] * + temp.ma[][] * ;
nn[cnt] = (s1 - ) / ;
LL s2 = temp.ma[][] * + temp.ma[][] * ;
xx[cnt++] = s2;
}
temp = temp*a;
}
}
int main()
{
init();
LL N;
while(cin>>N && N)
{
for(int i = ; i >= ; i--)
{
if(N >= nn[i])
{
cout<<nn[i]<<" "<<xx[i]<<endl;
break;
}
}
}
return ;
}
HDU 2281 Square Number Pell方程的更多相关文章
- HDU 6222 Heron and His Triangle (pell 方程)
题面(本人翻译) A triangle is a Heron's triangle if it satisfies that the side lengths of it are consecutiv ...
- hdu3293(pell方程+快速幂)
裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: ...
- hdu 5898 odd-even number 数位DP
传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...
- Pell方程及其一般形式
一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...
- hdu 2665 Kth number
划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...
- hdu 4670 Cube number on a tree(点分治)
Cube number on a tree Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- 主席树[可持久化线段树](hdu 2665 Kth number、SP 10628 Count on a tree、ZOJ 2112 Dynamic Rankings、codeforces 813E Army Creation、codeforces960F:Pathwalks )
在今天三黑(恶意评分刷上去的那种)两紫的智推中,突然出现了P3834 [模板]可持久化线段树 1(主席树)就突然有了不详的预感2333 果然...然后我gg了!被大佬虐了! hdu 2665 Kth ...
- Square Number & Cube Number
Square Number: Description In mathematics, a square number is an integer that is the square of an in ...
- 山东省第六届省赛 H题:Square Number
Description In mathematics, a square number is an integer that is the square of an integer. In other ...
随机推荐
- 五大最受欢迎的BUG管理系统
Google在中国大陆遭遇变故做出临时性的退出大陆市场,也使非常多忠实的用户受到小小的挫折,以本公司为例.原本的BUG都是记录在google的 EXCEL在线文档中,由于常常性的打不开.測试和开发组在 ...
- windows常用命令有哪些(整理)
windows常用命令有哪些(整理) 一.总结 一句话总结:其实这个好学,只要先弄懂主干,清除主干,那么枝叶的添加逻辑就很清除了 这种多内容的,散乱的,弄清除主干效率就高了 1.windows命令行的 ...
- 10.MongoDB:将Json数据直接写入MongoDB的方法
Json转Bson MongoDB中是以Bson数据格式进行存储的,Json字符串没有办法直接写入MongoDB 可以将Json字符串转换成DBObject或者Document,然后写入MongoDB ...
- 2015北京网络赛 G Boxes BFS+打表
G Boxes 题意:n个位置摆有n个箱子,每次移动只能把相邻的垒起来,且上面的必须小于下面的.求摆成升序需要移动多少步. 思路:这里的n很小,只有7.但是bfs最快的情况需要2s左右,所以就打表了. ...
- centos中mysql 安装以及配置,建库
1.检测系统内部有没有安装其他的mysql数据库 rpm -qa | grep mysql 然后如果有的话删除这些mysql yum remove 查出来的所有名字 2.彻底删除系统中mysql的目录 ...
- How Blink works
How Blink works Author: haraken@ Last update: 2018 Aug 14 Status: PUBLIC Working on Blink is not eas ...
- node.学习笔记(关于http2的讲解)
个人总结:读完这篇文章需要30分钟 http2部分很有学习价值,可以好好看. 用node搭建TCP服务器 用node搭建HTTP服务器 用node文件fs模块对文件读取,并用流的方式写入 用url路 ...
- [Python] Understand Scope in Python
Misunderstanding scope can cause problems in your application. Watch this lesson to learn how Python ...
- 具体解释window.location
window.location 对象所包括的属性 hash//从井号 (#) 開始的 URL(锚) host//主机名和当前 URL 的port号 hostname//当前 URL 的主机名 href ...
- HDU 5375 Gray code(DP)
题意:给一串字符串,里面可能出现0,1,?,当中问号可能为0或1,将这个二进制转换为格雷码后,格雷码的每位有一个权值,当格雷码位取1时.加上该位权值,求最大权值和为多少. 分析:比赛的时候愚了.竟然以 ...