hdu-5018
Revenge of Fibonacci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 703 Accepted Submission(s): 327
Problem Description
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F n = F n-1 + F n-2
with seed values F 1 = 1; F 2 = 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.
F n = F n-1 + F n-2
with seed values F 1 = 1; F 2 = 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
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
题目分析:这道题目刷的我都快哭了,一直不通过,一看别人的解释我才恍然大悟,尼玛的我竟然把a,b本身给忘了,这道题目错的值。。。
让我伤心了这么久。。。
代码附上:
#include<stdio.h>
int main(){
int T;
__int64 f1,f2,f3;
__int64 a,b,c;
int i;
scanf("%d",&T);
while(T--){
int flag=0;
scanf("%I64d%I64d%I64d",&a,&b,&c);
f1=a;
f2=b;
if(f1==c||f2==c){
printf("Yes\n"); //需要判断C是否是A或B,这代题目真把我给伤的不轻。。。。
continue;
}
for(;;i++){
f3=f1+f2;
f1=f2;
f2=f3;
if(f3==c){
flag=1;
break;
}
if(f3>c)
break;
}
if(flag==1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理