Pell方程(求形如x*x-d*y*y=1的通解。)
佩尔方程x*x-d*y*y=1,当d不为完全平方数时,有无数个解,并且知道一个解可以推其他解。 如果d为完全平方数时,可知佩尔方程无解。
假设(x0,y0)是最小正整数解。
则:
xn=xn-1*x0+d*yn-1*y0
yn=xn-1*y0+yn-1*x0
证明只需代入。 如果忘记公式可以自己用(x0*x0-d*y0*y0)*(x1*x1-d*y1*y1)=1 推。
这样只要暴力求出最小特解,就可以用快速幂求出任意第K个解。
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 2813 | Accepted: 1568 |
Description
Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):
6 8
35 49
Input
Output
Sample Input
Sample Output
6 8
35 49
这题可以得到佩尔方程s*s-8*t*t=1 ,s=2n+1,t=x (n表示总长,x表示取的n中某个位置)
s0=3,t0=1 然后就很好弄了
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std; int main(int argc, const char * argv[]) {
long long s0=;
long long t0=;
long long s1=;
long long t1=;
for(int i=;i<=;i++)
{
long long s,t;
s=s1*s0+*t1*t0;
t=t1*s0+t0*s1;
s1=s;
t1=t;
printf("%10lld%10lld\n",t,(s-)/);
//cout<<t<<" "<<(s-1)/2<<endl;
}
return ;
}
这题用暴力然后打表也是可以0MS过的。
Pell方程(求形如x*x-d*y*y=1的通解。)的更多相关文章
- Pell方程及其一般形式
一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...
- POJ 1320 Street Numbers Pell方程
http://poj.org/problem?id=1320 题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b 要使以a为分界的 前缀和 和 后缀和 相等 求a,b 因为序列很 ...
- POJ 2427 Smith's Problem Pell方程
题目链接 : http://poj.org/problem?id=2427 PELL方程几个学习的网址: http://mathworld.wolfram.com/PellEquation.html ...
- HDU 2281 Square Number Pell方程
http://acm.hdu.edu.cn/showproblem.php?pid=2281 又是一道Pell方程 化简构造以后的Pell方程为 求出其前15个解,但这些解不一定满足等式,判断后只有5 ...
- 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: ...
- hdu2281&&POJ1320——Pell方程
hdu2281 输入一个 $N$,求最大的 $n$($n \leq N$)和 $x$,使得 $x^2 = \frac{1^2+2^2+...+n^2}{n}$. 分析: 将右边式子的分子求和化简,有: ...
- [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程
题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...
- Sympy解方程-求极限-微分-积分-矩阵运算
简介 Sympy是一个Python的科学计算库,用一套强大的符号计算体系完成诸如多项式求值.求极限.解方程.求积分.微分方程.级数展开.矩阵运算等等计算问题.虽然Matlab的类似科学计算能力也很强大 ...
随机推荐
- Visio文件转EPS文件
Visio转eps by gaihf@水木 看了前人写的关于Visio转EPS的文章,但是实践过程中还是碰到几个棘手的问题.现在这些问题终于解决了,把自己的一点体会分享给大家. 很多人习惯用Visio ...
- 安装ansj分词器
项目地址:https://github.com/4onni/elasticsearch-analysis-ansj https://github.com/laigood/elasticsearch-a ...
- 2017.5.27 使用propagation实现:根据参数决定是否需要事务管理
1.功能描述 要实现rest接口:POST ***/entry,其中参数中有action参数. 当action=rollback时,批量新增出错时需要回滚. 当action!=rollback时,批量 ...
- setContentView
setContentView(R.layout.main)在Android里面,这句话是什么意思? R.layout.main是个布局文件即控件都是如何摆放如何显示的,setContentView就是 ...
- win10 如何配置 java jdk1.8环境变量(2017.8.17 )jdk1.8.0_144
win10 如何配置 java jdk 环境变量 2017.8.17 本篇还适用于 windows server 2012. windows server 2014+ 一.安装 下载 jdk 64位 ...
- 13.1Springboot 之 静态资源路径配置
Spring 静态资源路径是指系统可以直接访问的路径,且路径下的所有文件均可被用户直接读取. 在Springboot中默认的静态资源路径有:classpath:/META-INF/resources/ ...
- 求出数组中所有数字的和&&弹出层效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- MSSQL站库分离情况的渗透思路
本文转自:http://bbs.blackbap.org/thread-6203-1-2.html 1. 服务器属内网环境,站库分离,通过web.config找到数据库服务库SA帐号密码,成功添加用户 ...
- react-native-router-flux 页面跳转与传值
1.正向跳转假设情景:从Home页跳转到Profile页面,Profile场景的key值为profile 不带参数: Actions.profile 带参数: Actions.profile({'ke ...
- 【Excle】科学计数法快速还原
在Excle的单元格中,如果输入大于11位的数字,结果就会以E+形式显示 如果是单个输入的话,只需要把Excle中的单元格格式设置为文本即可,然后输入就不会出现科学计数法,但是有时候是从外部导入的序号 ...