uva 138 Street Numbers
2014-01-02 22:34
459 查看
感觉就是求1~ n 然后家在中间的k位置,求1~ k-1 的和等于k+1~n
题目:
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):
代码:
题目:
Street Numbers |
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).代码:
//Thu Jan 2 22:20:48 2014 //Author:Minshik #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <deque> #include <memory.h> #include <cctype> #include <iomanip> #include <cmath> using namespace std; // k^2 = (n+n^2)/2 int main() { int cnt = 0; long long n=2; while(cnt<10) { long long d = (n+pow(n,2))/2; long long c = sqrt(d); if( c*c == d ) { cout<<setw(10)<<c << setw(10)<<n<<endl; cnt++; } n++; } return 0; }
相关文章推荐
- UVa 138 Street Numbers / 佩尔方程
- UVA 138 - Street Numbers
- UVaOJ138 - Street Numbers
- UVa 11582 Colossal Fibonacci Numbers!
- Colossal Fibonacci Numbers! 巨大的斐波那契数 UVA - 11582
- UVA - 10392 Factoring Large Numbers
- UVa 11105 (筛法) Semi-prime H-numbers
- uva 763 Fibinary Numbers
- UVa 10539 - Almost Prime Numbers
- UVa 11582 - Colossal Fibonacci Numbers!(取模+周期)
- uva 138 - Street Numbers(等差数列求和)
- UVa 138 - Street Numbers
- UVA138---StreetNumber
- UVA-10539 Almost Prime Numbers
- UVa 10392 Factoring Large Numbers
- Street Numbers - UVa 138 水题
- UVA - 350 Pseudo-Random Numbers set的使用
- UVA - 471 Magic Numbers set + vector
- uva1406 - A Sequence of Numbers 树状数组
- UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)