佩尔方程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. Snapdragon profiler连不上 android手机

    adb devices也是空 开发者选项里面该开的都开了 就可以了 对了数据线不对也会连不上...

  2. JS中的柯里化及精巧的自动柯里化实现

    一.什么是柯里化? 在计算机科学中,柯里化(Currying)是把接受多个参数的函数变换成接受一个单一参数(最初函数的第一个参数)的函数,并且返回接受余下的参数且返回结果的新函数的技术.这个技术由 C ...

  3. 用PHP上传文件时$_FILES中error返回值详解

    用PHP上传文件时,我们会用程序去监听浏览器发送过来的文件信息,首先会通 过$_FILES[fieldName]['error']的不同数值来判断此欲上传的文件状态是否正常.$_FILES[field ...

  4. Gentoo:startx出现Failed to load module问题

    安装完xorg-server后,startx启动桌面环境,出现缺少模块错误. 查看log: cat /var/log/Xorg.0.log | grep EE [75.403] (EE) Failed ...

  5. magento安装wordpress

    说起来事实上很easy,如今简诉一下安装过程 1.到magento connect界面安装magento扩展,地址:http://www.magentocommerce.com/magento-con ...

  6. 51单片机 | 实现SMG12864液晶显示器操作

    ———————————————————————————————————————————— SMG12864液晶显示器 128*64个点位,可以显示图形或8*4个汉字 - - - - - - - - - ...

  7. 未能加载文件或程序集 MySql.Web

    偶然间碰到这个错误,找到一个临时的解决办法,真正的原因还不知道是什么,也不知道这种解决方法会不会对以后有什么副作用. “/”应用程序中的服务器错误. 配置错误 说明: 在处理向该请求提供服务所需的配置 ...

  8. JavaScript匿名函数与托付

    <1> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <!-- C#匿名函数--& ...

  9. 【SpringMVC学习11】SpringMVC中的拦截器

    Springmvc的处理器拦截器类似于Servlet 开发中的过滤器Filter,用于对处理器进行预处理和后处理.本文主要总结一下springmvc中拦截器是如何定义的,以及测试拦截器的执行情况和使用 ...

  10. mvc Ajax 跨域请求

    js端: $.ajax({ type : "get", async : false, url :url, data: 'bid=0&xingming=' + uName + ...