【vijos1543】Extreme Value Problem - Number Theory

background

Xiaoming's Mathematical Journey 2.

describe

It is known that m and n are integers and satisfy the following two conditions:
① m, n∈{1, 2, ..., K}
② (n^2-mn-m^2)^2=1
Make a program , for a given K, find a set of m and n that satisfy the above two conditions, and maximize the value of m^2+n^2. For example, if K=1995, then m=987 and n=1597, then m and n satisfy the condition, and the value of m^2+n^2 can be maximized.

Format

input format

Enter only one line, the value of K.

output format

The output is only one line, the value of m^2+n^2.

 

ideas

Adjacent two terms of Fibonacci can satisfy the condition, which is proved as follows:

$ n ^ 2-nm-m ^ 2 = n ^ 2-m (n + m) = (f_ {n}) ^ 2 - f_ {n-1} f_ {n + 1} = \ pm 1 $

So we just need to prove that $(f_{n})^2 - f_{n-1}f_{n+1}= \pm 1$

First $(f_{2})^2 - f_{1}f_{3}=1-2=-1 \ , \ (f_{3})^2 - f_{2}f_{4}=9-10 =-1$

We use mathematical induction, assuming that both $2n$ and $2n+1$ hold for $n(n\geq 2)$

则$(f_{2n})^2=(f_{2n-1}+f_{2n-2})^2=(f_{2n-1})^2+2f_{2n-1}f_{2n- 2}+(f_{2n-2})^2$

$=f_{2n-1}(f_{2n-1}+f_{2n-2})+f_{2n-1}f_{2n-2}+f_{2n-3}f_{2n-1}- 1$

$=f_{2n-1}f_{2n}+f_{2n-1}(f_{2n-2}+f_{2n-3})-1$

$=f_{2n-1}f_{2n}+(f_{2n-1})^2-1$

$=f_{2n-1}(f_{2n}+f_{2n-1})-1$

$=f_{2n-1}f_{2n+1}-1$

So $f_{2n}$ is established, and at this time it can be obtained again

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325158867&siteId=291194637