Uva 138-street Numbers (Pell equation)

Source: Internet
Author: User

Test instructions: A street with n houses numbered from 1 to n set someone's house number to satisfy 1+2+3+. (k-1) = (k+1) +...+n 10 groups of n,k values

The summation of both sides is simple and n^2+n-2k^2=0;  On both sides of the same multiply 4-4n^2+4n+1-8k^2=1; (2n+1) ^2-2 (2k) ^2=1;

Make x=2n+1 y=2k to x^2-2y^2=1; The equation, such as X^2-ny^2=1 (n is any positive integer), is called the Pell equation, and it is easy to find its pee (x0,y0)

Then Xi=x0*x (i-1) +n*y0*y (i-1)

Yi=y0*x (i-1) +x0*y (i-1), recursive can get all the solution of the equation

`#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include < queue> #include <stack> #include <map> #include <set> #define MAXN 10000002#define _ll __int64# Define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int> #define ull unsigned long Longu Sing namespace Std;int main () {int x[11]={3},y[11]={2};for (int i=1;i<=10;i++) {X[i]=x[i-1]*x[0]+2*y[i-1]*y[0];y[i] =x[i-1]*y[0]+y[i-1]*x[0];int n= (x[i]-1)/2,k=y[i]/2;printf ("%10d%10d\n", K,n);} return 0;}`

Uva 138-street Numbers (Pell equation)

Related Keywords:

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.