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 }
  • 相关阅读:
    Gradle 3.0 + 打包android module 为aar
    Android SELinux
    Mac OS X 修改文件创建时间、修改时间 + zip 过滤临时文件
    Android 应用运行期间系统配置(系统语言、字体大小等)改变引发的问题修改
    Docker 指令
    Ubuntu-spark安装
    Highcharts 二种导出方式
    使用Storyboard 创建ViewController
    数据持久化-Plist
    模拟器常用快捷键
  • 原文地址:https://www.cnblogs.com/moqitianliang/p/4698554.html
Copyright © 2011-2022 走看看