[Vijos] 1543 Extreme Value Problem (number theory + fib number)

Source: Internet
Author: User

Https://vijos.org/p/1543

A magic question ..

First, I forgot that N can be obtained for root, sad.

Then I typed the table and found that N and m are fib numbers ..

Strictly prove (the ghost knows why this is the right way, and how can it be the biggest if it can be replaced ?) :

(N ^ 2-mn-m ^ 2) ^ 2 = 1

(M ^ 2 + Mn-N ^ 2) ^ 2 = 1

(M (m + n)-N ^ 2) ^ 2 = 1

(M + n-n) (m + n)-N ^ 2) ^ 2 = 1

(M + n) ^ 2-N (m + n)-N ^ 2) ^ 2 = 1

Because (n' ^ 2-m' N'-m' ^ 2) ^ 2 = 1

Take n '= m + n, M' = n to enable the formula ..

Then there is violence.

#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <algorithm>#include <queue>using namespace std;typedef long long ll;#define rep(i, n) for(int i=0; i<(n); ++i)#define for1(i,a,n) for(int i=(a);i<=(n);++i)#define for2(i,a,n) for(int i=(a);i<(n);++i)#define for3(i,a,n) for(int i=(a);i>=(n);--i)#define for4(i,a,n) for(int i=(a);i>(n);--i)#define CC(i,a) memset(i,a,sizeof(i))#define read(a) a=getint()#define print(a) printf("%d", a)#define dbg(x) cout << (#x) << " = " << (x) << endl#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }#define printarr1(a, b) for1(_, 1, b) cout << a[_] << ‘\t‘; cout << endlinline const int getint() { int r=0, k=1; char c=getchar(); for(; c<‘0‘||c>‘9‘; c=getchar()) if(c==‘-‘) k=-1; for(; c>=‘0‘&&c<=‘9‘; c=getchar()) r=r*10+c-‘0‘; return k*r; }inline const ll max(const ll &a, const ll &b) { return a>b?a:b; }inline const int min(const int &a, const int &b) { return a<b?a:b; }ll k, a, b, ans;int main() {read(k);ll n=1, m=0;while(n+m<=k) {ll c=m;m=n;n+=c;}printf("%lld\n", m*m+n*n);return 0;}

Background

James's journey to mathematics 2.

Description

M and n are known as integers and meet the following two conditions:
① M, 'n ,..., K
② (N ^ 2-mn-m ^ 2) ^ 2 = 1
Compile a program to obtain a group of M and N that meet the preceding two conditions for the given K, and set the maximum value of M ^ 2 + N ^ 2. For example, if k = 1995, then M = 987, n = 1597, then M and N meet the conditions, and the M ^ 2 + N ^ 2 value can be maximized.

Format input format

Enter the value of K in only one row.

Output Format

Output only one line, m ^ 2 + N ^ 2 value.

Example 1 input 1 [copy]
1995
Sample output 1 [copy]
3524578
Restrictions

Each test point is 1 second.

Prompt

Source:
Shantou fxoi Group
Phoeagon
Thanx2 sivon
For tripley

vijos: 1543 Extreme Value Problem (number theory + fib number)

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.