zoukankan      html  css  js  c++  java
  • 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 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 and Output

    There is no input for this program. 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).

     

    题意:对于连续的数,从有一个数开始,他的前面数字只和与他后面数字只和相等,6,,8是1+2+3+4+5=7+8;

    tip:可以根据等差数列化简公式,成x*x-2*y*y=1;再由佩尔方程解

     

     

     1 #include<iostream>
     2 #include<iomanip>
     3 
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     for(int i=0,x0=3,y0=2,x=x0,y=y0,t;i<10;i++,x=t)
     9     {
    10         t=x*x0+2*y*y0;
    11         y=x*y0+y*x0;
    12         cout<<setw(10)<<y/2<<setw(10)<<(t-1)/2<<endl;
    13     }
    14     return 0;
    15 }
  • 相关阅读:
    第三方支付
    优化MySQL插入方法的五个妙招
    MySQL的数据类型和建库策略详解
    mysql 文本搜索
    mysql 存储过程
    mysql 游标的使用
    mysql 触发器
    mysql 保留点
    MySQL 使用硬链接配合truncate 删除2.2T的表
    25-ZigZag Conversion
  • 原文地址:https://www.cnblogs.com/moqitianliang/p/4698554.html
Copyright © 2011-2022 走看看