P1543Extremum Problem accepted Tags: [show tags]<textarea id="code" class="textbox"></textarea>Background
Xiao Ming's Math Tour 2.
Descriptive narrative
M, N is known as an integer, and the following two conditions are met:
①m, n∈1,2. ..., K
② (n^ 2-mn-m^2) ^2=1
Compile a procedure. For a given k, a set of M, N, which satisfies the above two conditions, and the maximum value of the m^2+n^2 is obtained. For example, if k=1995. m=987,n=1597, the M, n satisfies the condition, and the m^2+n^2 value is the largest.
Format input Format
Enter the value of only one row, K.
Output format
Outputs only one row, m^2+n^2 the value.
Example 1 example input 1[copy]
1995
Example output 1[copy]
3524578
Limit
1 seconds for each test pilot.
Tips
Source:
Shantou Fxoi Group
Phoeagon
ThanX2 Sivon
For Tripley
First of all, we have to find the relationship between the item and the column.
So you can get a[i] = 3 * A[i-1]-The number of items in the Fibonacci sequence is represented by I in a[i-2]{}
So that we can solve this problem.
#!/usr/bin/env python3#-*-coding:utf-8-*-k = Int (raw_input ()) A = 1b = 1ans = 2cnt = 2if k = = 1: print 2elif k = = 2 : print 5else: While True: if ans > k:break t = a a = a + b b = t ans + a cnt + = 1
c = 1 d = 1 for i in range (CNT): t = c c = c * d = t print C
vijos-p1543 extremum Problem (Fibonacci series + formula derivation + python)