Street Numbers
A computer programmer lives in a and houses numbered consecutively (from 1) down one side to the street. Every Evening She walks her dog by leaving her, house and randomly turning ET 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, the two sums are the same. Although this are determined in the "the" of her house number and "by" the number of houses in the street, she nevertheles S feels that this is a desirable property for her house to have and decides so all her subsequent houses should exhibit It.
Write a program to find pairs of the numbers that satisfy this condition. To start your list the two pairs are: [house number, last number]:
6 8
35 49
Input and Output
There is no input to this program. Output would consist of lines each containing a pair of numbers, each printed right justified in a field of Shown above).
Ask: Simple, find out 10 groups of k,n, meet 1 + 2 + ... + k = k + 1 + k + 2 + ... + N;
Idea: The application of Pell equation, using the previous solution to find the next solution to 10 groups can be.
Code:
#include <stdio.h>
#include <string.h>
int x, y, x0, y0, T, N;
int main () {
x = x0 = 3; y = y0 = 2; n = 2;
for (int i = 0; i < i + +) {
t = x * x0 + n * y * y0;
y = x * y0 + y * x0;
printf ("%10d%10d\n", Y/2, (t-1)/2);
x = t;
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/