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

Hint

For the third test case, the new Fibonacci sequence is: 2, 2, 4, 6, 10, 16, 26, 42, 68, 110…

水题,fibonacci数不会超过45个就会超范围了,所以最多只有45个有用。

代码:

//0ms
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long a[50];
int main()
{
    int t;
    long long c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d%I64d",&a[0],&a[1],&c);
        if(a[0]==c||a[1]==c)
        {
            printf("Yes\n");
            continue;
        }
        int sign=0;
        for(int i=2;i<50;i++)
        {
            a[i]=a[i-1]+a[i-2];
            if(a[i]==c)
            {
                sign=1;
                break;
            }
        }
        if(sign)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}
时间: 2024-10-07 19:17:30

hdu 5018 Revenge of Fibonacci(BestCoder Round #10)的相关文章

HDU 5018 Revenge of Fibonacci(数学)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 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). ---

hdu 5018 Revenge of Fibonacci

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5018 思路:直接计算判断就是啦,注意一点要判断给出的A,B.... code #include<cstdio> #include<iostream> #include<cmath> #include<algorithm> #include<cstring> using namespace std; int main() { int F[1000];

HDU 4099 Revenge of Fibonacci

Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others) Total Submission(s): 2027    Accepted Submission(s): 475 Problem Description The well-known Fibonacci sequence is defined as following: Here w

HDU 4099 Revenge of Fibonacci Trie+高精度

Revenge of Fibonacci Problem Description The well-known Fibonacci sequence is defined as following: Here we regard n as the index of the Fibonacci number F(n).  This sequence has been studied since the publication of Fibonacci's book Liber Abaci. So

hdu 4099 Revenge of Fibonacci Trie树与模拟数位加法

Revenge of Fibonacci 题意:给定fibonacci数列的前100000项的前n位(n<=40);问你这是fibonacci数列第几项的前缀?如若不在前100000项范围内,输出-1: 思路:直接使用数组模拟加法,再用Trie树插入查找即可:但是一般使用new Trie()的代码都是MLE的.反而我之前写的,直接得到数组大小的maxnode版本的内存可以接受:并且还有一点就是前40位的精度问题:由于是自己计算出来的finboncci数列,并不是系统给的,所以1的进位不会形成递推

HDU 5224 Tom and paper(BestCoder Round #40)

题目链接:Tom and paper 题面: Tom and paper Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 679    Accepted Submission(s): 432 Problem Description There is a piece of paper in front of Tom, its length

hdu 4099 Revenge of Fibonacci(字典树)

Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 204800/204800 K (Java/Others) Total Submission(s): 2355    Accepted Submission(s): 587 Problem Description The well-known Fibonacci sequence is defined as following: Here w

hrbust 1209/hdu 4099 Revenge of Fibonacci【字典树+大数】

Revenge of Fibonacci Time Limit: 5000 MS Memory Limit: 204800 K Total Submit: 37(24 users) Total Accepted: 18(17 users) Rating:  Special Judge: No Description The well-known Fibonacci sequence is defined as following: F(0) = F(1) = 1 F(n) = F(n - 1)

HDU 5268 ZYB loves Score (BestCoder Round#44)

题目链接:ZYB loves Score 题面: ZYB loves Score Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 395    Accepted Submission(s): 232 Problem Description One day,ZYB participated in the BestCoder Contest