任意门: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. PHP高级工程师面试 - 笔试题

    Part1:HTTP协议 1.状态码的含义 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求 ...

  2. sprintf 格式化字符串

    好久没写博客了,又遇到自己觉得很傻的问题,格式化字符串还要找下 定义和用法 sprintf() 函数把格式化的字符串写入变量中. arg1.arg2.++ 参数将被插入到主字符串中的百分号(%)符号处 ...

  3. JAVA基础之——方法直接用类名.的理解

    前言 在java中经常遇到使用classname.method()的方式调用方法,哪些场景需要用到呢,如下: 某些操作不依赖具体实例 某个方法是用频率较高,或者方法本身通用性较强,无需初始化类成员变量 ...

  4. poj Strange Way to Express Integers 中国剩余定理

    Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 8193   ...

  5. <!DOCTYPE> 标签是什么

    DOCTYPE 标签,是html文档的类型声明(document type declaration,所谓声明,也就是宣称我他妈是谁),用来告诉浏览器,使用什么样的文档类型定义(Document Typ ...

  6. Python爬虫教程-00-写在前面

    鉴于好多人想学Python爬虫,缺没有简单易学的教程,我将在CSDN和大家分享Python爬虫的学习笔记,不定期更新 基础要求 Python 基础知识 Python 的基础知识,大家可以去菜鸟教程进行 ...

  7. Intent和BroadcastReceiver

    Intent简介 Intent是一种消息传递机制,作用: 使用类名显示启动一个特定的Service或Activity 启动Activity或Service来执行一个Intent 广播某个事件已经发生 ...

  8. forkjoin框架疑问记录

    今天在看jdk1.7的forkjoin框架时候,里面有个例子如下: product类: public class Product { private String name; private doub ...

  9. androidcookie存储sqllite

    /**声明一些数据库操作的常量*/  private static SQLiteDatabase mDatabase = null;  private static final String DATA ...

  10. Software Testing Techniques Homework 1

    I have met some errors in recent years, one of them which impress me most. It happend when I try to ...