Fibonacci Sum
InterviewTime limit1sMemory limit1024 MB
Given k and x, decide whether x equals the sum of exactly k Fibonacci numbers, where the same term may be reused.
- Level
Easy3 of 10
- Topics
- Brute force, Hash map
- Solved
- No attempts yet
Problem
Given two positive integers and , determine whether can be written as the sum of exactly terms of the Fibonacci sequence. A term may be chosen more than once.
The Fibonacci sequence is defined by and for .
Input
The first line contains the number of test cases .
Each of the next lines contains , the number of Fibonacci terms to use, and , the target positive integer, separated by a space.
Output
Print lines. On line , print the answer for the -th test case: YES if can be made by adding exactly Fibonacci terms, and NO otherwise.
The output is case-sensitive. Yes, yes, and similar forms are not accepted.
Hint
The input can exceed the range of an int. Using long long or another 64-bit type is recommended.
The output is case-sensitive. Yes and yes are not accepted as correct answers.