Street Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2529   Accepted: 1406

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

Source

 
题目要求解1+2+3+...+n=(n+1)+....+m.
要使1+2+3+...+n=(n+1)+....+m.那么n(n+1)/2=(m-n)(n+n+1)/2,即(2m+1)^2-8n^2=1.令x=2m+1,y=n,有x^2-8y^2=1.因此就变成解佩尔方程,而x1=3,y1=1.根据迭代公式:
xn=xn-1*x1+d*yn-1*y1
yn=xn-1*y1+yn-1*x1.

已知x1=3,y1=1;

有佩尔方程的迭代公式:x[n]=x[n-1]*x1+d*y[n-1]*y1.   y[n]=y[n-1]*y1+yn-1]*x1

故有:x[n+1]=3x[n]+8y[n];

y[n+1]=x[n]+3y[n];

就可以求出前十组解。
#include<stdio.h>
#include<math.h>
int main()
{
int x1=,y1=,d=,x,y,px=,py=;
for(int i=;i<=;i++)
{
x=x1*px+d*y1*py;
y=y1*px+x1*py;
printf("%10d%10d\n",y,(x-)/);
px=x;py=y;
}
return ;
}

Pell方程,由费马提出,但后来欧拉误记为佩尔提出,并写入他的著作中。后人多称佩尔方程。

设d是正整数,且非平方数。
下面的不定方程称为佩尔(Pell)方程:
(1)一定有无穷多组正整数解
这是初等数论中最经典的内容之一。
 
 
 
 
 

POJ 1320 Street Numbers 解佩尔方程的更多相关文章

  1. POJ 1320 Street Numbers 【佩尔方程】

    任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  2. POJ 1320 Street Numbers(佩尔方程)

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3078   Accepted: 1725 De ...

  3. POJ 1320 Street Numbers Pell方程

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

  4. POJ1320 Street Numbers【佩尔方程】

    主题链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输 ...

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

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

  6. POJ 1320:Street Numbers

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2753   Accepted: 1530 De ...

  7. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  8. 2010辽宁省赛G(佩尔方程)

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

  9. C语言之基本算法26—佩尔方程求解

    //穷举法! /* ====================================================== 题目:求佩尔方程x*x-73*y*y=1的解. =========== ...

随机推荐

  1. Ubantu E325 错误的解决办法

    这个错误是由于未正确关闭文本编辑器导致的: 图一 解决办法:退出后输入 sudo vim /etc/hosts 图二 直接输入 D 即可! 注意:退出文本编辑器的正确方式是:ESC键 + :wq. 我 ...

  2. 虚拟接VMnet1 和VMnet8的区别

    vmnet1是host-only,也就是说,选择用vmnet1的话就相当于VMware给你提供了一个虚拟交换机,仅将虚拟机和真实系统连上了,虚拟机可以与真实系统相互共享文件,但是虚拟机无法访问外部互联 ...

  3. Autofac小例子

    AutoFac是.net平台下的IOC容器产品.今天学习一下它的使用方法. 1.最简单的使用. public interface ITestDao { string SayHello(); } pub ...

  4. 一个知乎日报pwa

    前几天写了一篇文章关于如何实现一个简单版的pwa应用,端午撸了一个简易版知乎日报pwa. 关于如何写一个pwa,这里就不多介绍了,请移步这里.应用使用vue+vuex+axios,API这里,这里做了 ...

  5. C#异步了解一下

    如何让你的代码在“同一时间”干着两件件事呢?比如说,在初始化加载配置的同时,UI界面能够响应用户的各种点击事件.而不置于卡死,特别是出现如下面这种情况的时候,对于用户来说是很崩溃的.

  6. 关于python的闭包与装饰器的实验

    首先看闭包,在嵌套函数内添加返回值,可以通过外部函数读取内部函数信息 #encoding=utf-8 #闭包应用 #先定义闭包函数,并使用 def outer(func): def inner(): ...

  7. 第二篇 Postman的高阶使用之配置全局变量及局部变量的调用及设置方法(手动方法)

    第五篇主要写了关于postman的基本使用,重点是如果发送json请求,为什么要将发送json请求呢, 一是目前大多数的请求已经倾向于发送json格式,二是本人太懒了,不想一个字段一个字段的添加到参数 ...

  8. 1066 Root of AVL Tree (25 分)(平衡二叉树)

    就是AVL的模板题了 注意细节 #include<bits/stdc++.h> using namespace std; typedef struct node; typedef node ...

  9. 机器学习/逻辑回归(logistic regression)/--附python代码

    个人分类: 机器学习 本文为吴恩达<机器学习>课程的读书笔记,并用python实现. 前一篇讲了线性回归,这一篇讲逻辑回归,有了上一篇的基础,这一篇的内容会显得比较简单. 逻辑回归(log ...

  10. gcc6.3编译c++11的程序链接opencv时字符型函数未定义

    在Windows下编写图像处理程序,由于要使用regex,升级了mingw,编译c++11代码.之前代码中使用了opencv2.4.10,一直运行良好,升级编译器以后发现了错误:undefined r ...