佩尔方程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个解。

Street Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2813   Accepted: 1568

Description

A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. One night she adds up the street numbers of the houses she passes (excluding her own). The next time she walks the other way she repeats this and finds, to her astonishment, that the two sums are the same. Although this is determined in part by her house number and in part by the number of houses in the street, she nevertheless feels that this is a desirable property for her house to have and decides that all her subsequent houses should exhibit it. 
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

There is no input for this program.

Output

Output will consist of 10 lines each containing a pair of numbers, in increasing order with the last number, each printed right justified in a field of width 10 (as shown above).

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的通解。)的更多相关文章

  1. Pell方程及其一般形式

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

  2. POJ 1320 Street Numbers Pell方程

    http://poj.org/problem?id=1320 题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b  要使以a为分界的 前缀和 和 后缀和 相等 求a,b 因为序列很 ...

  3. POJ 2427 Smith's Problem Pell方程

    题目链接 :  http://poj.org/problem?id=2427 PELL方程几个学习的网址: http://mathworld.wolfram.com/PellEquation.html ...

  4. HDU 2281 Square Number Pell方程

    http://acm.hdu.edu.cn/showproblem.php?pid=2281 又是一道Pell方程 化简构造以后的Pell方程为 求出其前15个解,但这些解不一定满足等式,判断后只有5 ...

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

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

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

  7. hdu2281&&POJ1320——Pell方程

    hdu2281 输入一个 $N$,求最大的 $n$($n \leq N$)和 $x$,使得 $x^2 = \frac{1^2+2^2+...+n^2}{n}$. 分析: 将右边式子的分子求和化简,有: ...

  8. [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程

    题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...

  9. Sympy解方程-求极限-微分-积分-矩阵运算

    简介 Sympy是一个Python的科学计算库,用一套强大的符号计算体系完成诸如多项式求值.求极限.解方程.求积分.微分方程.级数展开.矩阵运算等等计算问题.虽然Matlab的类似科学计算能力也很强大 ...

随机推荐

  1. 在eclipse中使用Lombok

    1.下载Lombok.jar http://projectlombok.googlecode.com/files/lombok.jar2.运行Lombok.jar: java -jar  D:\001 ...

  2. 读取Properties文件简易代码

    public class Utils { private static Properties props = new Properties(); static { ClassLoader classL ...

  3. [转载]Linux 卸载JDK并安装新版本JDK (rpm,tar)

    FROM:http://josh-persistence.iteye.com/blog/1908549 一.查看Jdk的安装路径: whereis javawhich java (java执行路径)e ...

  4. 针对ecshop错误404页面的优化

    在ecshop系统当中,比如你随意将商品详细页面的地址中的ID修改为一个不存在的商品ID,ecshop会自动跳转到首页.ecshop在这方面做得非常的差,甚至导致了很多的站不被搜索引擎收录.最模板提供 ...

  5. 我与小娜(36):人机大战第五局,AlphaGo必胜!

    我与小娜(36):人机大战第五局,AlphaGo必胜!       小娜知道,细致阅读论文"Mastering the game of Go with deep neural network ...

  6. JS杂技之无中间变量的值交换方式

    从http://www.cnblogs.com/liuyitian/p/4081517.html#3074553看到一种无中间变量的值交换方式,具体如下: var a = 1;var b = 2;a ...

  7. Binder与interface

    在Interface中,asBinder函数涌来将服务类接口类型转换为IBinder类型: 相反的,asInterface函数用来将Ibinder类型转换为服务接口类型

  8. SQL JOB 调用 SSIS package 权限问题

    来自: http://www.cnblogs.com/sodacc/archive/2012/11/26/2789135.html 第一次用SQL给SSIS包排JOB的时候,都会遇到这样一个问题:单独 ...

  9. InnoDB事务和锁

    InnoDB支持事务,MyISAM不支持事务. 一.事务的基本特性 ACID特性 1.原子性(Atomicity):事务是一个原子操作单元,其对数据的修改,要么全都执行,要么全都不执行. 2.一致性( ...

  10. 关于ionic中几个问题

    第一.每个页面的独立样式style标签不能写在ion-view外面,否则会出现路由问题,建议写在ion-content后面,例如下面的例子中,如果style但在ion-view中的话会出想路由问题,显 ...