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

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

题意是一个计算机程序员住在一个门牌号(从1开始计)连续的街道上,每天晚上她都在这个街道上从头走到尾,有一天晚上她把她走过的门牌号相加起来,下一次她走另一条路还是相加门牌号,令她吃惊的是(我都不知道这有什么好吃惊的),两个和是相等的。让打出表house number,last number

题意的意思翻译过来就是1+2+...+x = x+(x+1)+(x+2)...+y

求x,y。

方程就变为x*(x+1)/2 = (x+y)(y-x+1)/2 => y^2+y-2*x^2=0 => (2*y+1)^2-8*x^2=0

做这道题的收获就是通过这道题了解了佩尔方程,它是一个解x^2-d*y^2=1这类方程的方法。

说起来这个佩尔方程也是逗,是费马老人家提出来的,结果欧拉记错了,写在他的书中了。有意思的是,可能是欧拉的影响力太大了,之后大家还是把费马提出的方法叫佩尔方程了,真替费马感到不值啊(之后再一想想,我有什么资格替费马感到不值。。。人家一个大定理青史留名,我一个程序员还在做POJ的题。。。做得还挺好玩)。

咳咳,反正佩尔方程的意思就是x^2-d*y^2=1的第一个解x0,y0已知的话,其余的值有一个递推公式了:

X(n)=X(n-1)*x0+d*Y(n-1)*y0

Y(n)=X(n-1)*y0+Y(n-1)*x0

知道了这个之后,程序就好写了。以后记住解x^2-d*y^2=1的方程有一个简便算法~

代码:

#include<iostream>
#include<iomanip>
#pragma warning(disable:4996)
using namespace std; int main()
{
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout); long long i,x0=3,y0=1,last_x=3,last_y=1,x,y;
for(i=1;i<=10;i++)
{
x=last_x*x0+8*last_y*y0;
y=last_x*y0+last_y*x0; cout<<setw(10)<<y<<setw(10)<<(x-1)/2<<endl; last_x=x;
last_y=y;
}
system("pause");
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. 如何使用Dubbo服务和集成Spring
  2. Effective C++ -----条款26:尽可能延后变量定义式的出现时间
  3. CSS3属性
  4. jQuery对Table一个字段排序
  5. ASP.NET 时间方法大全
  6. webdriver 操作 Firefox 在关闭浏览器时弹出 “Plugin Container for Firefox已停止工作” 处理办法。
  7. Apache XAMPP Fails to start under Windows XP
  8. BZOJ1642: [Usaco2007 Nov]Milking Time 挤奶时间
  9. 边记边学PHP-(十五)MySQL数据库基础操作2
  10. Newtonsoft.Json使用
  11. JavaScript一个生成文档目录的实例
  12. mysql数据库的安装与配置
  13. 20155336 《Java程序设计》实验二 (Java面向对象程序设计)实验报告
  14. (转)MapReduce Design Patterns(chapter 4 (part 2))(八)
  15. Spring.net ObjectWrapper对象的包装(反射机制)有点明晰方便
  16. JVM 统计监测命令
  17. HDOJ.1051 Wooden Sticks (贪心)
  18. [存一下]iptables模块
  19. MySQL 中文显示乱码
  20. 智课雅思词汇---十八、前缀peri是什么意思

热门文章

  1. Python 关于super在多继承中的解析
  2. mysql#自定义序列
  3. priority_queue优先级队列总结
  4. mysql里的序列应用详解
  5. mysql 单表索引优化
  6. 浏览器 canvas下载图片 网络错误
  7. LINQ---查询表达式的结构
  8. brew services start redis 无法使用问题排查
  9. 功耗极低非接触 13.56mhz读卡芯片:SI522
  10. xfpt 连接Linux失败问题