Algorithm title: UVA 138

Source: Internet
Author: User

Street Numbers

A computer programmer lives in a and houses numbered consecutively (from 1) down one side to the street. Every Evening She walks her dog by leaving her, house and randomly turning ET 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, the two sums are the same. Although this are determined in the "the" of her house number and "by" the number of houses in the street, she nevertheles S feels that this is a desirable property for her house to have and decides so all her subsequent houses should exhibit It.

Write a program to find pairs of the numbers that satisfy this condition. To start your list the two pairs are: [house number, last number]:

6 8
35 49

Input and Output

There is no input to this program. Output would consist of lines each containing a pair of numbers, each printed right justified in a field of Shown above).

Ask: Simple, find out 10 groups of k,n, meet 1 + 2 + ... + k = k + 1 + k + 2 + ... + N;

Idea: The application of Pell equation, using the previous solution to find the next solution to 10 groups can be.

Code:

#include <stdio.h>
#include <string.h>
  
int x, y, x0, y0, T, N;
int main () {
    x = x0 = 3; y = y0 = 2; n = 2;
    for (int i = 0; i < i + +) {
    t = x * x0 + n * y * y0;    
    y = x * y0 + y * x0;
    printf ("%10d%10d\n", Y/2, (t-1)/2);
    x = t;
    }
    return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.