vijos-p1543 extremum Problem (Fibonacci series + formula derivation + python)

Source: Internet
Author: User

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)

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.