poj_1320_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 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

题意 k号房子分开n栋房子,前k-1栋和等于k+1到第n栋。输出k,n。
网上题解大多瞎XX扯X,证明不完整,推导胡说八道直接给出佩尔方程。我直接暴力打印前几组找到了规律
      6         8
        35        49
       204       288
      1189      1681
到这里我就发现了,
204=35*6-6  288=204+35+49
1189=204*6-35  1681=1189+204+288
a[i]=a[i-1]*6-a[i-2]
b[i]=a[i]+a[i-1]+b[i-1]


#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define N 1000010
using namespace std;
typedef long long ll;
int a[11];
int b[11];
int main()
{
   // freopen("dataout.txt","w",stdout);
    a[0]=6;
    a[1]=35;
    b[0]=8;
    b[1]=49;
    printf("%10d%10d\n",6,8);
    printf("%10d%10d\n",35,49);
    for(int i=2;i<10;i++)
    {
        a[i]=a[i-1]*6-a[i-2];
        b[i]=a[i]+a[i-1]+b[i-1];
        int x=a[i],y=b[i];
        printf("%10d%10d\n",a[i],b[i]);
    }

}



posted @ 2017-11-26 20:03  会飞的雅蠛蝶  阅读(142)  评论(0编辑  收藏  举报