佩尔方程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. 改变PS1变量的颜色

    2016.1.11今天学了改变PS1的颜色,怎么增加PS1变量找到文件(.bash_profile),或者bashrc export PS1="\[\e[32;1m\]Test $PWD&g ...

  2. mysql行转列,单列转多行

    行转列 使用CASE语句: SELECT SUM(CASE USER_NAME='A' THEN KILLS END) AS 'A', SUM(CASE USERNAME='B' THEN KILL ...

  3. javascript正则表达式小技巧

    一.中括号[]里面的特殊字符是不用转义的,例如[/].[.].[*].[?].[+]都是可以直接匹配对应的字符\ . *?+.下面是测试结果: 所以,/[\d.]/这个正则表达式实际上是匹配数字字符或 ...

  4. JavaScript 闭包 面试题

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  5. 【Excle数据透视表】如何将价格小于5000的显示为红色“不达标”

    例如下图:需要将价格小于5000的设置为低价格 步骤 单击"价格"列任意单元格→右键→数字格式→自定义→在类型下的文本框写入:[>=5000]G/通用格式;[红色][< ...

  6. 微软在GitHub上开放源代码

    https://github.com/MSOpenTech 点击链接:openFrameworks :https://github.com/openframeworks/openFrameworks ...

  7. SQLServer 2017安装时的错误:Polybase要求安装Oracle JRE 7更新51或更高版本

    2016应该也有这个问题 下载JDK7就可以了(我装10是不可以解决的) 重新运行下 安装完后再安装SSMS 附: MS SQL SERVER 2017全套下载地址(含JDK7.SSMS.KEY): ...

  8. .NET CORE 2.0小白笔记(二):VS插件 ReSharper Ultimate 2017 安装破解

    采用Use License Server方式激活,如果有多台要激活的可以用一个当服务器 下载网盘:链接: https://pan.baidu.com/s/1nvacvKP 密码: ipxc 版本:Je ...

  9. 转:HTTP协议--- multipart/form-data请求分析

    转自:http://blog.csdn.net/five3/article/details/7181521 首先来了解什么是multipart/form-data请求: 根据http/1.1 rfc ...

  10. Qt Creator中增加新的ui文件时报错

    原因分析:moc_开头的文件编译过程中没有又一次生成导致. 解决的方法:删除编译产生的build目录.又一次编译就可以. 错误类型截图例如以下: 这个问题的解决.使得能够在不论什么时候都能够在proj ...