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. 使用testng.xml组织测试用例

    测试用例类TeseNG.java: import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.open ...

  2. 第三十篇 面向对象的三大特性之继承 supre()

    继承 一 .什么是继承? 类的继承跟现实生活中的父.子.孙子.重孙子的继承关系一样,父类又称基类. Python中类的继承分为:单继承 和  多继承. # 定义父类 class ParentClass ...

  3. gcc options选项的优化及选择

    gcc options选项的优化 -c和-o都是gcc编译器的可选参数[options] -c表示只编译(compile)源文件但不链接,会把.c或.cc的c源程序编译成目标文件,一般是.o文件.[只 ...

  4. Python攻击

    python   DOS攻击 2版本 #!/usr/bin/env python import socket import time import threading #Pressure Test,d ...

  5. Daily Scrum02 12.01

    今天是2013年12月的第一天,希望大家都有一个新的开始,一起努力!     Member Today's Task Tomorrow's Task 李孟 Task 856: 熟悉单元测试方法熟悉单元 ...

  6. html页面简单制作示例

    内有表格布局,具体见 链接: https://pan.baidu.com/s/1V7IcxQ5M-iXVdlzuf8bo-A 密码: 8dp8

  7. poj1789 Truck History最小生成树

    Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20768   Accepted: 8045 De ...

  8. 指针C语言

    一.PTA实验作业 题目一:6-7输出月份英文名 1.PTA提交列表 2.设计思路和流程图 这题只需补充子函数,定义指针数组month[12],分别从一月到十二月,再定义一个字符,让它为NULL,当输 ...

  9. 基于SDN的IP RAN网络虚拟化技术

    http://www.zte.com.cn/cndata/magazine/zte_technologies/2014/2014_4/magazine/201404/t20140421_422858. ...

  10. elementUI默认样式修改不成功的问题

    问题: login.vue中引入<style lang="postcss" src="./login.css" scoped></style& ...