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; }