算法:搜索;

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

Revenge of Fibonacc的更多相关文章

  1. HDU 3341 Lost's revenge(AC自动机+DP)

    Lost's revenge Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  2. HDU 5019 Revenge of GCD(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...

  3. L - Abbott's Revenge(比较复杂的bfs)

    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UV ...

  4. hdu 4099 Revenge of Fibonacci 大数+压位+trie

    最近手感有点差,所以做点水题来锻炼一下信心. 下周的南京区域赛估计就是我的退役赛了,bless all. Revenge of Fibonacci Time Limit: 10000/5000 MS ...

  5. HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)

    Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...

  6. HDU5087——Revenge of LIS II(BestCoder Round #16)

    Revenge of LIS II Problem DescriptionIn computer science, the longest increasing subsequence problem ...

  7. HDU5086——Revenge of Segment Tree(BestCoder Round #16)

    Revenge of Segment Tree Problem DescriptionIn computer science, a segment tree is a tree data struct ...

  8. UVA 816 - Abbott&#39;s Revenge(BFS)

    UVA 816 - Abbott's Revenge option=com_onlinejudge&Itemid=8&page=show_problem&category=59 ...

  9. hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法

    Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输 ...

随机推荐

  1. java 代码格式(转)

    //转至博客:http://developer.51cto.com/art/201202/320317.ht /** * Java编码格式个人推荐,参考JDK源码和Hyperic HQ源码(原spri ...

  2. Raspberry PI Model B+ (LCD显示CPU温度)

    Title:Raspberry PI Model B+ (LCD显示CPU温度)  --2015-01-29 17:44 买了块连接Raspberry PI Model B+的LCD显示器,上面没写C ...

  3. hdu 1051Wooden Sticks

    #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000 using na ...

  4. 转一篇:Hyper-V和VMware的高可用实时迁移技术详解

    ESX里以集群的ha.drs.dpm功能实现 HYPER-V里以集群+共享存储实现. ~~~~~~~~~~ 微软公司的Hyper-V虚拟化管理程序一经面世就引发了业界的普遍关注.本文意在对Hyper- ...

  5. 复位应答ATR的基本结构和数据元

    根据定义,复位应答是一系列字节的值,这些字节是由卡作为对复位命令的响应发送给接口设备的 ,在I/O电路上,每个字节在一个异步字符中传输.每个成功的复位操作,都会导致I/O上的一个初始字符TS,TS后面 ...

  6. @action 注解

    ================================================= 下载 注解配置 private String fileName; private String co ...

  7. Extjs4 中在指定光标处插入值

    var rulearea = Ext.getCmp(文本域Id); var rulevalue = rulearea.getValue();// 获取文本textarea 里面的值 var start ...

  8. Delphi 使用自定义消息

    Delphi 使用自定义消息   1.先用Const 定义一个常量,例如 const WM_MyMessage=WM_USER+$200; 2.在要实现的unit中定义一个私有方法 procedure ...

  9. Delphi——Window 消息 - 转载▼

    Delphi是Borland公司的一种面向对象的可视化软件开发工具. Delphi集中了Visual C++和Visual Basic两者的优点:容易上手.功能强大,特别是在界面设计.数据库编程.网络 ...

  10. DLL入门浅析(5)——使用DLL在进程间共享数据

    转载自:http://www.cppblog.com/suiaiguo/archive/2009/07/21/90734.html 在Win16环境中,DLL的全局数据对每个载入它的进程来说都是相同的 ...