POJ 1320 Street Numbers 【佩尔方程】

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

New Zealand 1990 Division I,UVA 138

题意概括:

有 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 ];

原文地址:https://www.cnblogs.com/ymzjj/p/10549729.html

时间: 2024-10-13 15:11:51

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

POJ1320 Street Numbers【佩尔方程】

题目链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输出前10组满足要求 的(N,M). 思路: 要使 1 + 2 + - + N = (N+1) + - + M,那么 N*(N+1)/2 = (M-N)(M+N+1)/2,即 (2*M+1)^2 - 8*N^2 - 1,令x = 2*M + 1,y = N,就有x^2 - 8*y^2 = 1,就变成了典型的

Uva 138-Street Numbers(佩尔方程)

题目链接:点击打开链接 题意: 一条街上有n个房子编号从1到n 设某人的房子编号为k 求满足 1+2+3+..(k-1)=(k+1)+...+n 的10组n,k值 两边求和化简得 n^2+n-2k^2=0;  两边同乘4  -> 4n^2+4n+1-8k^2=1;  -> (2n+1)^2-2(2k)^2=1; 令 x=2n+1 y=2k 得 x^2-2y^2=1; 形如 x^2-ny^2=1 (n为任意正整数) 的方程称为佩尔方程,很容易求出其最小解 (x0,y0) 然后 xi=x0*x(i

poj 1320

Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2806   Accepted: 1565 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

Street Numbers

 Street Numbers 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 str

(Incomplete) UVa 138 Street Numbers

方法:暴力 设home的序号为n,街尾序号为N,列出方程 (n-1)*n/2 = (N+n+1)*(N-n)/2, 化简得 2*n*n = (N+1)*N.枚举N再检查是否有解.可以直接求,或者打表. code: #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <string> #include <vector>

[NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程

题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8871535 当d为完全平方数时无解 将√d表示成连分数的形式,例如: 当d不为完全平方数时,√d为无理数,那么√d总可以表示成: 记 当n为偶数时,x0=p,y0=q:当n为奇数时,x0=2p2+1,y0=2pq 求d在1000以内佩尔方程的最小正整数解的c++打表程序(正常跑比较慢,这个题需要离

poj 3252 Round Numbers 【推导&#183;排列组合】

以sample为例子 [2,12]区间的RoundNumbers(简称RN)个数:Rn[2,12]=Rn[0,12]-Rn[0,1] 即:Rn[start,finish]=Rn[0,finish]-Rn[0,start-1] 所以关键是给定一个X,求出Rn[0,X] 现在假设X=10100100  这个X的二进制总共是8位,任何一个小于8位的二进制都小于X 第一部分,求出长度为[0,7]区间内的二进制是RoundNumber的个数  对于一个长度为Len的二进制(最高位为1),如何求出他的Rou

POJ 1515 Street Directions --一道连通题的双连通和强连通两种解法

题意:将一个无向图中的双向边改成单向边使图强连通,问最多能改多少条边,输出改造后的图. 分析: 1.双连通做法: 双连通图转强连通图的算法:对双连通图进行dfs,在搜索的过程中就能按照搜索的方向给所有边定向,其中桥不能改造,只能保留双向边. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #includ

POJ 1715 Hexadecimal Numbers 组合数学

POJ 1715 Hexadecimal Numbers 组合数学 题目地址 题意: 一个十六进制,最多8位而且每一位都不能重复,求所有符合的数中第n大的数.注意不能有前导0. 分析: 可以发现,第i位的任何一个取值,都有P(unused, i - 1)个数字串,只要从高位向低位,从F到1找过去,看第n个是否在这个区间里面,如果没有的话就把那位置为0,然后找下一位就行了. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1715.c