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. Memcache启动&amp;存储原理&amp;集群

    一. windows下安装启动 首先将memcache的bin文件夹增加到Path环境变量中.方便后面使用命令: 然后运行 memcached –dinstall 命令安装memcache的服务: 然 ...

  2. Python使用Redis实现一个简单作业调度系统

    Python使用Redis实现一个简单作业调度系统 概述 Redis作为内存数据库的一个典型代表,已经在非常多应用场景中被使用,这里仅就Redis的pub/sub功能来说说如何通过此功能来实现一个简单 ...

  3. win32下实现透明窗体

    最開始写透明窗体的代码,在百度了之后,找到了SetLayeredWindowAttributes()这一个函数,可是因为网上案列的缺少,使得非常多人无法非常好的使用这一个方法,我花了几天的时间写了一个 ...

  4. Ubuntu14环境下minigui安装问题记录--object.lo错误

    minigui3.0.12在Ubuntu14上面编译只是去?出现这个错误:object.h:275:9: error: incompatible types when assigning to typ ...

  5. quartz-misfire 错失、补偿执行

    调度(scheduleJob)或恢复调度(resumeTrigger,resumeJob)后不同的misfire对应的处理规则 misfire产生的条件是:到了该触发执行时上一个执行还未完成,且线程池 ...

  6. HDU 4513 吉哥系列故事――完美队形II

    http://acm.hdu.edu.cn/showproblem.php?pid=4513 吉哥系列故事——完美队形II Time Limit: 3000/1000 MS (Java/Others) ...

  7. Android开发当中Parcelable接口的使用

    本文转载于:http://www.2cto.com/kf/201205/132814.html 本文稍微做了些修改 android提供了一种新的类型:Parcel.本类被用作封装数据的容器,封装后的数 ...

  8. 【hdu 1429】胜利大逃亡(续)

    [Link]: [Description] 给你一个n*m的格子; 里面有钥匙,以及钥匙能开的门; 以及墙,以及起点,以及出口; 问你从起点出发,到出口的话,能不能在t时间内到; [Solution] ...

  9. win10 WmiPrvSE.exe WMI Provider 占用CPU过高的问题

    重启 Windows Management Instrumentation 服务 重启 WMI service.   + ,输入: "services.msc" ,按 . 在 服务 ...

  10. Peer To Peer——对等网络

    今年的考试.大问题没怎么出现. 就是考英语第二天的下午,发生网络阻塞的现象,不影响大局.可是事出有因,我们还是须要看看是什么影响到了考生抽题.最后查了一圈,发现其它几场的英语考试听力都是19M大小,而 ...