任意门: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. 云主机安装Tomcat上传自己的网站

    前几天在DigitalOcean上买一个云服务器(1g内存,1核,25gssd,1tb流量,一个月5$,按天收费),用github的students developer package里面的优惠码拿到 ...

  2. SublimeText3 插件的使用和本身的配置

    --------------------20180109----------------------- Part1:如何设置代码字体变大变小 1.点击菜单栏 Sublime Text 中prefere ...

  3. code.google.com certificate error: certificate is for www.google.com

    有时候我们会碰到下面错误:code.google.com certificate error: certificate is for www.google.com,类似如下: D:\>go ge ...

  4. git杂记-撤销操作

    覆盖上一次的提交或重新更新提交说明 $ git commit --amend -m '我再次提交啦,上一次的提交已经不见啦.这是一个危险的操作哦.哈哈,其实并不危险,也是可以数据恢复的啦' 取消已暂存 ...

  5. Bzoj4766: 文艺计算姬(Matrix-tree/prufer)

    BZOJ 答案就是 \(n^{m-1}m^{n-1}\) \(prufer\) 证明: \(n\) 中的数字出现 \(m-1\) 次,\(m\) 中出现 \(n-1\) 次,根据 \(prufer\) ...

  6. Luogu4887 第十四分块(前体)

    sto \(lxl\) orz 考虑莫队,每次移动端点,我们都要询问区间内和当前数字异或有 \(k\) 个 \(1\) 的数字个数 询问 \([l,r]\) 可以再次离线,拆成询问 \([1,l-1] ...

  7. Wireframe Process

  8. 【Yii系列】错误处理和日志系统

    缘起 跟随上一章的脚步,上一章中,我们主要讲解了在用户发起请求,解析请求,服务器反馈请求以及session的一些知识点,这过程中,难免会遇到一些问题,比方说数据库查询失败,用户输入导致脚本出错,网络问 ...

  9. SQL SERVER占用CPU过高优化S

    https://www.cnblogs.com/yuekong2010/p/6628001.html 然后使用下面语句看一下各项指标是否正常,是否有阻塞,正常情况下搜索结果应该为空. 1 SELECT ...

  10. Android根据URL下载文件保存到SD卡

    //下载具体操作 private void download() { try { URL url = new URL(downloadUrl); //打开连接 URLConnection conn = ...