CUGBACM15 class BC 10th ahdu 5018 Revenge of Fibonacci

Source: Internet
Author: User
Revenge of Fibonacci Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 1288 Accepted Submission (s): 605


Problem Description in mathematical terms, the sequence Fn of FIBONACCI numbers are defined by the recurrence relation
Fn = Fn-1 + Fn-2
With seed values F1 = 1; F2 = 1 (sequence A000045 in OEIS).
---Wikipedia

Today, Fibonacci takes revenge on you. Now the first and the elements of Fibonacci sequence have been redefined as A and B. You have a to check if C are in the new Fibonacci sequence.
Input The first line contains a single integer T, indicating the number of test cases.

Each test case is only contains three integers A, B and C.

[Technical specification]
1.1 <= T <= 100
2.1 <= A, B, C <= 1 000 000 000

Output for each test case, output "Yes" if C is in the new Fibonacci sequence, otherwise "No".
Sample Input
3 2 3 5 2 3 6 2 2 110
Sample Output
Yes No Yes Hint for the third Test case, the new Fibonacci sequence Is:2, 2, 4, 6, 10, 16, 26, 42, 68, 110 ... Test instructions: AB is the first two of the Fibonacci sequence and asks you if C is the number in the Fibonacci sequence.

Idea: Water problem, direct simulation can

#include <iostream> #include <set> #include <map> #include <stack> #include <cmath> # Include <queue> #include <cstdio> #include <bitset> #include <string> #include <vector> # Include <iomanip> #include <cstring> #include <algorithm> #include <functional> #define PI ACOs ( -1) #define EPS 1e-8 #define INF 0x3f3f3f3f #define DEBUG (x) cout<< "---" <<x<< "---" <<endl typedef
Long Long ll;

using namespace Std;
    int main () {int t;
    ll A, B, C;
    scanf ("%d", &t);
        while (t--) {scanf ("%lld%lld%lld", &a, &b, &c);
        if (c = = A | | c = b) {printf ("yes\n");
        } else if (C < a) {printf ("no\n");
            } else {ll xx = A;
            int flag = 0; while (xx <= c) {if (xx = = c) {flag =1;
                } xx = a + b;
                A = b;
            b = xx;
            } if (flag = = 1) {printf ("yes\n");
            } else {printf ("no\n");
}}} return 0; }


Related Article

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.