Revenge of Fibonacci(杭电5018)

Revenge of Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 721    Accepted Submission(s): 332

Problem Description

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<stdio.h>
#include<string.h>
int s[10000];
int main()
{
    int n,i,a,b,c,k;
	scanf("%d",&n);
	while(n--)
	{
		memset(s,0,sizeof(s));
	    scanf("%d%d%d",&a,&b,&c);
		if(a==c||b==c)  //本题容易少考虑的情况。
		printf("Yes\n");
		else
		{
			k=0;
		    s[1]=a,s[2]=b;
			for(i=3;;)
			{
			    s[i]=s[i-1]+s[i-2];
				if(s[i]<c)
				{
				   i++;
				}
				if(s[i]==c)
				{
				   k=1;
				   break;
				}
				if(s[i]>c)
				{
				   break;
				}
			}
			if(k==1)
			printf("Yes\n");
			else
			printf("No\n");
		}
	}
	return 0;
}
时间: 2025-01-02 14:11:06

Revenge of Fibonacci(杭电5018)的相关文章

Hat&#39;s Fibonacci(杭电1250)

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7854    Accepted Submission(s): 2551 Problem Description A Fibonacci sequence is calculated by adding the previous two members th

杭电5018--Revenge of Fibonacci

Revenge of Fibonacci Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 6   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description In mathematical te

hdu 5018 Revenge of Fibonacci(BestCoder Round #10)

Revenge of Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 372    Accepted Submission(s): 177 Problem Description In mathematical terms, the sequence Fn of Fibonacci numbers is define

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

大菲波数 【杭电-HDOJ-1715】 附题

/* 大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11168    Accepted Submission(s): 3782 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Input

杭电 1715

大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 11143    Accepted Submission(s): 3772 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Input 输入第

杭电1316

How Many Fibs?Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3804    Accepted Submission(s): 1498 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn := f

杭电1715(大菲波数)

点击打开杭电1715 Problem Description Fibonacci数列,定义如下: f(1)=f(2)=1 f(n)=f(n-1)+f(n-2) n>=3. 计算第n项Fibonacci数值. Input 输入第一行为一个整数N,接下来N行为整数Pi(1<=Pi<=1000). Output 输出为N行,每行为对应的f(Pi). Sample Input 5 1 2 3 4 5 Sample Output 1 1 2 3 5 代码实现: import java.math.B