任意门: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 ];

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

  1. POJ 1320 Street Numbers Pell方程

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

  2. POJ 1320 Street Numbers 解佩尔方程

    传送门 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2529   Accepted: 140 ...

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

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

  4. POJ 1320:Street Numbers

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

  5. POJ1320 Street Numbers【佩尔方程】

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

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

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

  7. Poj 2247 Humble Numbers(求只能被2,3,5, 7 整除的数)

    一.题目大意 本题要求写出前5482个仅能被2,3,5, 7 整除的数. 二.题解 这道题从本质上和Poj 1338 Ugly Numbers(数学推导)是一样的原理,只需要在原来的基础上加上7的运算 ...

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

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

  9. POJ 1320

    作弊了--!该题可以通过因式分解得到一个佩尔方程....要不是学着这章,估计想不到.. 得到x1,y1后,就直接代入递推式递推了 x[n]=x[n-1]*x[1]+d*y[n-1]*y[1] y[n] ...

随机推荐

  1. bnu 4060 奇偶性,异或运算

    Plants vs. Zombies Time Limit: 5000ms Memory Limit: 2048KB   64-bit integer IO format: %lld      Jav ...

  2. lambda 表达式学习笔记

    在Java中传递一个代码段并不容易,不能直接传递代码段.Java是一个面向对象语言,所以必须构造一个对象,这个对象的类需要一个方法能包含所需的代码.lambda的出现有效的解决这个问题,让代码变得更加 ...

  3. UOJ169. 【UR #11】元旦老人与数列

    传送门 考虑用 \(segment~tree~beats\) 那一套理论,维护区间最小值 \(mn\) 和严格次小值 \(se\) 那么可以直接 \(mlog^2n\) 维护前三个操作 考虑维护历史最 ...

  4. BZOJ1031 [JSOI2007]字符加密

    Description 喜欢钻研问题的JS同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法 :把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作 ...

  5. 苹果ios,下拉菜单错位的问题(目前iphone x没发现有这个问题)

    苹果手机,点击下拉框,再点击确认按钮,页面位置错乱(感觉背景整体往上移动了一段距离,并且,页面所有的元素都往上移了一定的距离),导致手机页面底部留白的问题,并且,元素实际位置跟页面位置不一致. 解决方 ...

  6. drupal7 jquery脚本忽然不运行

    jquery脚本经过调试,确认没有错误,但是最最近一次,调整了引入的次序,目的是方便我识别哪些js是我自己写的,哪些是前端给的,便于后期维护时,迅速找到自己写的部分. 调整引入次序前: 调整后(调整后 ...

  7. Drupal7安装注意事项

    1.在php.ini中将max_execution_time = 2400,memory_limit = 256M

  8. 将本地项目放到GitHub上托管并展示

    忽然知道自己写的项目效果可以放到网上让别人看到之后,就已经迫不及待了.不墨迹,先去了解GitHub得知,它很强(牛逼),我理解的是这是一个托管平台,可以把自己本地的项目通过git放到上面,你需要新建一 ...

  9. Avalon探索之旅

    avalon2是一款基于虚拟DOM与属性劫持的 迷你. 易用. 高性能 的 前端MVVM框架, 拥有超优秀的兼容性, 支持移动开发, 后端渲染, WEB Component式组件开发, 无需编译, 开 ...

  10. java 通过调用存储过程获取结果集

    一般在java中,数据查询是通过Statement, PreparedStatement获取结果集,今天向大家介绍通过CallableStatement调用存储过程,从而获取结果集.        本 ...