Revenge of Fibonacc

时间:2022-12-14 09:29:23

算法:搜索;

In mathematical terms, the sequence Fn of Fibonacci numbers is 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 two elements of Fibonacci sequence has been redefined as A and B. You have to check if C is in the new Fibonacci sequence.





Input

The first line contains a single integer T, indicating the number of test cases.



Each test case 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

代码:

#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stdio.h>
using namespace std;
long long n,m,k;
long long s;
long long dfs(long long x,long long y)
{
s=x+y;
if(s==k) return 1;
if(x==k) return 1;
if(y==k) return 1;
if(s>k&&k!=x&&k!=y) return 0;
dfs(y,s);
}
int main()
{
int t;
cin>>t;
while(t--)
{ cin>>n>>m>>k;
int ans=dfs(n,m);
if(ans) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}