The Pell equation (the general solution for finding the shape as X*x-d*y*y=1. )

Source: Internet
Author: User

The Pell equation X*x-d*y*y=1, when D is not a complete square number, there are countless solutions, and knowing that a solution can push other solutions. If D is a complete square number, there is no solution to the Pell equation.

The hypothesis (x0,y0) is the smallest positive integer solution.

The

Xn=xn-1*x0+d*yn-1*y0

Yn=xn-1*y0+yn-1*x0

The proof is simply to substitute. If you forget the formula you can use (x0*x0-d*y0*y0) * (x1*x1-d*y1*y1) =1 push.

So as long as the violent effort to make the smallest special solution, we can use the fast power to find out any of the K solutions.

Street Numbers
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 2813 Accepted: 1568

Description

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 she house and randomly turning left or right and walking to the end of the Stre 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-the-repeats this and finds-to-her astonishment, which is the sums. Although this was determined in part by her house number and in part by the number of houses in the street, she nevertheles S feels that's a desirable property for she house to has 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 pairs is: (house number, last number):
         6         8
49

Input

There is no input for this program.

Output

Output would consist of lines each containing a pair of numbers, in increasing order with the last number, each printed Right justified in a field of width ten (as shown above).

Sample Input

Sample Output

         6         8        49

This problem can be obtained by the Pell equation S*s-8*t*t=1, s=2n+1,t=x (n = total length, x indicates a position in N)

S0=3,t0=1 and then it's fine.

#include <iostream>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<algorithm>using namespacestd;intMainintargcConst Char*argv[]) {    Long Longs0=3; Long Longt0=1; Long Longs1=3; Long Longt1=1;  for(intI=1; i<=Ten; i++)    {        Long Longs,t; S=s1*s0+8*t1*t0; T=t1*s0+t0*S1; S1=s; T1=T; printf ("%10lld%10lld\n", T, (S-1)/2); //cout<<t<< "" << (s-1)/2<<endl;    }    return 0;}

This problem with violence and then hit the table can also be 0MS.

The Pell equation (the general solution for finding the shape as X*x-d*y*y=1. )

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.