Revenge of Fibonacc

news/2024/7/6 3:02:38

算法:搜索;

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



转载于:https://www.cnblogs.com/wangyumin/p/5323420.html


http://www.niftyadmin.cn/n/1126567.html

相关文章

JDBC访问数据库查询信息的步骤(硬编码格式)

1 Class.forName()加载驱动 2 DriverManager获取Connect连接 3 创建Statement执行SQL语句 4 返回ResultSet查询结果 5释放资源 package cn.tree.dao;import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; im…

弟子规 解说

大家好&#xff01;在还没有讲《弟子规》之前&#xff0c;我想我们先应该建立一个正确的观念。什么观念&#xff1f;有很多人他都误以为在现在文明的社会&#xff0c;高科技、高物质享受的社会当中&#xff0c;传统的文化已经不符合时代潮流。所以有很多古圣先贤所留下来的这些…

Mermaid from《Pirates of the Caribbean: On Stranger Tides》

下午陪女友去看了<加勒比海盗4>&#xff0c;片子还算不错。美人鱼很惊艳&#xff0c;甚至一定程度上抢了Joony Deep的风头。当然人鱼之恋也很扯.... 给一个建议是不要去看3D版的&#xff0c;顺便放几张图片&#xff1a; 转载于:https://www.cnblogs.com/macleanoracle/ar…

php捕获网络页面

<?php$url http://jwzx.cqupt.edu.cn/pubYxKebiao.php?typezy&yx06;$html file_get_contents( $url );$html iconv("GBK","UTF-8//IGNORE",$html) ;//转换编码 ?> 转载于:https://www.cnblogs.com/steamed-bread/p/5296375.html

php小问题总结

html charsetutf-8&#xff0c;mysql 连接时候charsetutf8.2.转载于:https://blog.51cto.com/7080696/1903679

JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试?

JSP连接各类数据库大全SQLServer2000 JDBC驱动的完整安装及测试说明SQLServer2000 JDBC驱动的完整安装及测试说明&#xff08;转载&#xff09;一、下载SQLSERVER2000的jdbc驱动程序。在微软站点就有这个驱动程序&#xff1a;Window操作系统http://www.uncj.com/upload/files/m…

我的书橱

转载于:https://www.cnblogs.com/macleanoracle/archive/2013/03/19/2967991.html

怎么用ABBYY重组PDF文档

2019独角兽企业重金招聘Python工程师标准>>> ABBYY PDF Transformer是一款可创建、编辑以及将PDF文件转换为其他可编辑格式的通用工具&#xff0c;除此之外&#xff0c;还可以使用ABBYY PDF Transformer重新组织PDF文档&#xff0c;如在文档中添加页面、更换页面顺序…