Topic Link: Click to open the link
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)