任意门:http://poj.org/problem?id=1320

Street Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3181   Accepted: 1776

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

题意概括:

有 M 个房子, 编号为 1~M,是否存在 1+2+3+...+ (N-1) == (N+1)+(N+2)+...+(M);

求解前十个 N, M;

解题思路:

两个等差数列求和,化简可得:

(2M+1)^2 - 8N^2 = 1;

令 X = 2M+1, Y = N ;

特解: X0 = 3, Y0 = 1;

根据佩尔方程的递推式:

X[ n+1 ] = X[ n ] * X0 + D * Y[ n ] *  Y0;

Y[ n+1 ] = X[ n ] * Y0 + X0 * Y[ n ];

最新文章

  1. MS SQL 字符拆分存处理
  2. shellinabox安装
  3. LeetCode41 First Missing Positive
  4. C#学习笔记(第1周作业)
  5. Unity3D之如何创建正确的像素比在屏幕上
  6. python 数据运算
  7. API练习_图形
  8. [三]基础数据类型之Integer详解
  9. 【AGC015E】Mr.Aoki Incubator DP
  10. 通过Socket实现TCP编程,用户登录之服务器相应客户端,客户端和服务端之间的通信
  11. Oracle_安装问题
  12. maven 排除test测试类
  13. PAT 乙级 1061. 判断题(15)
  14. docker(一)
  15. 【bzoj4765】 普通计算姬
  16. kafka生产者和消费者
  17. Code Signal_练习题_commonCharacterCount
  18. MySQL学习之路(一)——初涉MySQL。
  19. SQL命令行修改数据库
  20. location.false(true)

热门文章

  1. mysql分表,批量生成数据
  2. 腾讯企业邮箱报错 "smtp.exmail.qq.com"port 465, isSSL false
  3. linux下elasticsearch集成mongodb详细教程
  4. java类加载机制及方法调用
  5. java util 中set,List 和Map的使用
  6. let 和 var 区别
  7. Web开发须知的浏览器内幕 缓存与存储篇(1)
  8. 利用Ogr将Kml转为Shape【1】
  9. 小程序-报错 xxx is not defined (已解决)
  10. 使用PermissionsDispatcher轻松解决Android权限问题