KEI Day (c group) (3)

topic

The door opened, there really is a big hall. Unfortunately auditorium addition to the central piece of parchment and a fine slate pencil, as well as around a few skeletons nothing. Is this the royal heritage? It found small FF do not believe, he carefully read the content on parchment, written inside the ancient people have not been able to solve the problem, as long as people aim to lift this question will answer with a slate pencil can be written on parchment reach the royal treasure chamber. And when small FF picked slate pencil, just opened the door suddenly shut the boulder. The little FF and realize that it is a few skeletons in his previous adventurers here, I am afraid is not being able to crack this question and dying in here. Small FF grew more and more scared, and hurried to contact you, in order to save your life, and you would like him even 50-50 ...... It seems that you have to help him up again. Parchment problems as follows:
      a known x, y is an integer and satisfy the following two conditions:
      1. x, y [epsilon] [1..k], and x, y, the Z [epsilon] K;
      2. (X ^ 2 - xy - y ^ 2) ^ 2 = 1
      gives you an integer k, find a set of x satisfying the above conditions, y and such that the maximum value of x ^ 2 + y ^ 2 a.
      When the small FF get an answer, with a slate pencil to write answers on the parchment, then we can reach the royal heritage sites.

Entry

An integer k

Export

Output file only one row, two integers;
two represent integers x and y. x, y separated by a space between.

Sample input

1995

Sample Output

1597 987

Data range limit

Data of 30%: 2 <= k <= 10 ^ 4.
100% of the data: 2 <= k <= 10 ^ 18.

prompt

Z is the mathematical symbol inside a set of integers that are integers xyk

Thinking

This formula will not question me down, but according to the laws hit the table found the answer in a Fibonacci number.

Code

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
long long k,i;
struct h
{
    long long num1;
    long long num2;
    long long num;
};
h fb[90];
int main()
{
    fb[0].num1=1;
    fb[0].num2=1;
    fb[0].num=1;
    cin>>k;
    while(fb[i].num<k)
    {
        i++;
        fb[i].num1=fb[i-1].num2;
        fb[i].num2=fb[i-1].num1+fb[i-1].num2;
        fb[i].num=fb[i-1].num+fb[i].num1;
    }
    cout<<fb[i].num1<<" "<<fb[i].num2<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/abcdhh/p/11308824.html