zoukankan      html  css  js  c++  java
  • [解题报告]138 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

    给出程序媛的门牌号N和最后一栋房子的门牌号K

    出前10组N和K,使得1+2+3+...+N = N+(N+1)+...+K

    #include<stdio.h>
    int main()
    {
        int cnt=0;
        long long int k=6;
        while (cnt<1)
         {
            long long int n=(long long int)sqrt(2*k*k);
            if(2*k*k==n*(n+1)) 
            printf("%10lld%10lld\n",k,n),cnt++;
            k++;
        }
        return 0;
    }
  • 相关阅读:
    clientX和clientY属性需要注意的地方
    事件冒泡 --- 仿select下拉框
    body和document的梗
    完美运动框架
    仿flash运动框架
    多物体运动框架
    Computed Styles
    悬浮框
    【一起驴友】公司笔试
    Client Dimensions , offsetHeight , scrollTop 属性详解
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2928147.html
Copyright © 2011-2022 走看看