本文共 1422 字,大约阅读时间需要 4 分钟。
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, each printed right justified in a field of width 10 (as shown above).
【题意】
有m个街道,程序员的家在n点,满足1+2+...+n-1=n+1+......+m;
求n,m;
此时方程为:(2*m+1)^2-8*n^2=1;
x=2*m+1,y=n;
最小的一组解为:x1=3,y1=1;
m=(x-1)/2,n=y;
循环求出十组解即可,注意格式/
#includeusing namespace std;int main(){ ios::sync_with_stdio(false); int x,y; int x1=3,y1=1; for(int i=1;i<=10;i++) { x=x1*3+8*y1; y=x1+3*y1; cout< < < <<(x-1)/2<
转载地址:http://xvyzi.baihongyu.com/