POJ1320 UVA138 Street Numbers【Pell方程+数学】
2018-02-16 21:57
519 查看
Street Numbers
DescriptionA 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):
35 49
SourceNew Zealand 1990 Division I,UVA 138
问题链接:POJ1320 UVA138 Street Numbers
问题简述:(略)
问题分析:
佩尔方程指形如X^2-d*Y^2=1的不定方程。
这个题是求解两个不相等的正整数n,m,使得:
1+2+3+…+n=(n+1)+(n+2)+…+m。
用高斯速算公式分别计算两边式子,合并化简后可以得到:(2*m+1)^2-8*n^2=1,即佩尔方程形式。
迭代计算公式如下:
Xn+1=3Xn+8Yn.
Yn+1=Xn+3Yn
其中X1=3,Y1=1。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:/* POJ1320 UVA138 Street Numbers */
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 10;
int main()
{
int x1 = 3, y1 = 1, x, y;
for(int i=0; i<N; i++) {
x = 3 * x1 + y1 * 8;
y = x1 + 3 * y1;
printf("%10d%10d\n", y, (x - 1) / 2);
x1 = x;
y1 = y;
}
return 0;
}
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3055 | Accepted: 1712 |
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 49InputThere is no input for this program.OutputOutput 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 InputSample Output 6 8
35 49
SourceNew Zealand 1990 Division I,UVA 138
问题链接:POJ1320 UVA138 Street Numbers
问题简述:(略)
问题分析:
佩尔方程指形如X^2-d*Y^2=1的不定方程。
这个题是求解两个不相等的正整数n,m,使得:
1+2+3+…+n=(n+1)+(n+2)+…+m。
用高斯速算公式分别计算两边式子,合并化简后可以得到:(2*m+1)^2-8*n^2=1,即佩尔方程形式。
迭代计算公式如下:
Xn+1=3Xn+8Yn.
Yn+1=Xn+3Yn
其中X1=3,Y1=1。
程序说明:(略)
题记:(略)
参考链接:(略)
AC的C++语言程序如下:/* POJ1320 UVA138 Street Numbers */
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 10;
int main()
{
int x1 = 3, y1 = 1, x, y;
for(int i=0; i<N; i++) {
x = 3 * x1 + y1 * 8;
y = x1 + 3 * y1;
printf("%10d%10d\n", y, (x - 1) / 2);
x1 = x;
y1 = y;
}
return 0;
}
相关文章推荐
- UVA 138 - Street Numbers (数论)
- POJ 1320 Street Numbers 解佩尔方程
- Uva 138-Street Numbers(佩尔方程)
- UVa 138 - Street Numbers
- uva 138 Street Numbers
- UVA 138 Street Numbers
- UVA - 138 Street Numbers 公式题
- POJ 1320:Street Numbers——佩尔方程
- POJ1320 Street Numbers(佩尔方程)
- UVA-1388 && POJ-3154 墓地雕塑(数学)
- POJ 1320-Street Numbers(解佩尔方程)
- POJ - 1320 - Street Numbers - (佩尔方程)
- poj 1320 Street Numbers 解pell方程
- UVA 138 Street Numbers
- UVA138- Street Numbers
- UVa 138 - Street Numbers
- uva 138 - Street Numbers
- POJ 1320 Street Numbers 笔记
- POJ 1320 Street Numbers 佩尔方程
- HDU1046 POJ1450 UVALive2334 ZOJ1037 Gridland【数学计算+水题】