现在的位置: 首页 > 综合 > 正文

HDU 5018 Revenge of Fibonacci 斐波拉契数

2018年01月19日 ⁄ 综合 ⁄ 共 1072字 ⁄ 字号 评论关闭

Revenge of Fibonacci

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 797    Accepted Submission(s): 360

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

/*
HDU 5018 斐波拉契数 
给定初始的两个数 判断第三个数是否在是该数列 
*/
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int t;
	__int64 a,b,c,sum;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%I64d%I64d%I64d",&a,&b,&c);
		sum=a+b;
		if(a==c||b==c)
		{
			printf("Yes\n");
			continue;
		}
		while(sum<c)
		{
			a=b;
			b=sum;
			sum=a+b;
		}
		if(sum==c)
			printf("Yes\n");
		else
			printf("No\n");	
	}
	return 0;
} 
 

抱歉!评论已关闭.