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

浙公网安备 33010602011771号