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. 隐藏WPF ToolBar 左侧的移动虚线和右侧的小箭头

    原文:隐藏WPF ToolBar 左侧的移动虚线和右侧的小箭头   上面的图是两个工具栏的链接处.   去除蓝色部分的方法是 设置工具栏的ToolBarTray.IsLocked附加选项为True   ...

  2. 一步一步学Linq to sql(五):存储过程

    普通存储过程 首先在查询分析器运行下面的代码来创建一个存储过程: create proc sp_singleresultset as set nocount on select * from cust ...

  3. easyui 验证动态添加和删除问题

    $.extend($.fn.validatebox.methods, { remove: function(jq, newposition){ return jq.each(function(){ $ ...

  4. NSDictionary底层实现原理

    一言以蔽之:在OC中NSDictionary是使用hash表来实现key和value的映射和存储的. 那么问题来了什么是hash表呢? 哈希表(hash表): 又叫做散列表,是根据关键码值(key v ...

  5. android开源项目之OTTO事件总线(二)官方demo解说

    官方demo见  https://github.com/square/otto 注意自己该编译版本为2.3以上,默认的1.6不支持match_parent属性,导致布局文件出错. 另外需要手动添加an ...

  6. 『AngularJS』理解$Scope

    理解$Scope 执行概要 在AngularJS,一个子scope通常原型继承于它的父scope.应用于这个规则的表达式是一个使用scope:{...}的指令,这将创建一个『孤岛』scope(非原型继 ...

  7. 「暑期训练」「基础DP」 Piggy-Bank (HDU-1114)

    题意与分析 完全背包问题. 算法背包九讲里面都有提到过,我自己再说下对完全背包的理解. 为什么01背包中遍历状态从VV到00?考虑一下基本方程$dp[i][j]=max(dp[i-1][j-w[i]] ...

  8. jmeter之HTTP请求

    1.添加一个线程组:Test plan_添加_Threads(users)_线程组(右键操作),如下图: 2.添加一个HTTP请求:线程组_添加_sample_HTTP请求(右键操作),如下图: 3. ...

  9. 6.1 python+appium元素定位方式(登录app)

    1.0.0     :常见的十种元素定位方式 .driver.find_element_by_id() #id定位 .driver.find_element_by_name() #name定位(已经凉 ...

  10. python终极篇 --- django 初识

    1. 下载: 命令行: pip install django==1.11.15 pip install -i 源 django==1.11.15 pycharm settings 解释器 点+号 输入 ...