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方程的更多相关文章

  1. 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 ...

  2. hdu3293(pell方程+快速幂)

    裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

  3. hdu 5898 odd-even number 数位DP

    传送门:hdu 5898 odd-even number 思路:数位DP,套着数位DP的模板搞一发就可以了不过要注意前导0的处理,dp[pos][pre][status][ze] pos:当前处理的位 ...

  4. Pell方程及其一般形式

    一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...

  5. hdu 2665 Kth number

    划分树 /* HDU 2665 Kth number 划分树 */ #include<stdio.h> #include<iostream> #include<strin ...

  6. 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/ ...

  7. 主席树[可持久化线段树](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 ...

  8. Square Number & Cube Number

    Square Number: Description In mathematics, a square number is an integer that is the square of an in ...

  9. 山东省第六届省赛 H题:Square Number

    Description In mathematics, a square number is an integer that is the square of an integer. In other ...

随机推荐

  1. hdu5336XYZ and Drops

    题意:给出r*c的网格,有的网格为空.有的有水.再给出一个爆炸点,从这个点向四周爆出四个水滴,若碰到水则融为一体,若碰到其它水滴直接跑过去互不影响.每秒可跑一格,若水中水滴数量超过4则爆开.问T秒后网 ...

  2. Canvas与Paint的0基础使用

    看了非常多android自己定义方面的资料,了解了非常多原理,遇到人家自己定义的东西也可以看得懂,可是.当自己去自己定义的时候.发现脑袋一片空白,所以就先从认识Canvas和Paint開始吧! Can ...

  3. Qt中事件分发源码剖析

    Qt中事件分发源码剖析 Qt中事件传递顺序: 在一个应该程序中,会进入一个事件循环,接受系统产生的事件,而且进行分发,这些都是在exec中进行的. 以下举例说明: 1)首先看看以下一段演示样例代码: ...

  4. C语言:具体解释指针

    指针应该算得上是c语言的精华,但也是难点. 非常多教程或者博客都有对其具体的解说与分析. 我这一节的内容,也是解说指针.但我会尽量使用图解的方式,使大家非常easy理解及掌握. 一.基本使用 先来看看 ...

  5. 简单日志LogHelper

    public static class LogHelper { //日志存储路径 private static string LogPath = Path.Combine(AppDomain.Curr ...

  6. 关于springmvc重定向后Cannot create a session after the response has been committed问题

    首先先上代码吧,我在用springmvc进行response.sendRedirect(url);操作后报了Cannot create a session after the response has ...

  7. 使用PyV8模块破解网站加密cookie

    PyV8是Chromium中内嵌的javascript引擎,号称跑的最快.PyV8是用Python在V8的外部API包装了一个python壳,这样便可以使python可以直接与javascript操作 ...

  8. 洛谷——P1043 数字游戏

    https://www.luogu.org/problem/show?pid=1043 题目描述 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要 ...

  9. 洛谷 P3130 [USACO15DEC]计数haybalesCounting Haybales

    P3130 [USACO15DEC]计数haybalesCounting Haybales 题目描述 Farmer John is trying to hire contractors to help ...

  10. jQuery源码06-jQuery = function(){};给JQ对象,添加一些方法和属性,extend : JQ的继承方法,jQuery.extend()

    /*! * Includes Sizzle.js 选择器,独立的库 * http://sizzlejs.com/ */ (function( window, undefined ) { //" ...