Under construction

Still being built. Things may change

Fibonacci Sum

Interview

Time limit1sMemory limit1024 MB

Summary
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 kk and xx, determine whether xx can be written as the sum of exactly kk terms of the Fibonacci sequence. A term may be chosen more than once.

The Fibonacci sequence is defined by F_1=F_2=1F\_1 = F\_2 = 1 and F_n=F_n−1+F_n−2F\_n = F\_{n-1} + F\_{n-2} for n≥3n \geq 3.

Input

The first line contains the number of test cases TT. (1≤T≤100)(1 \leq T \leq 100)

Each of the next TT lines contains kk, the number of Fibonacci terms to use, and xx, the target positive integer, separated by a space. (1≤k≤3; 1≤x≤1016)(1 \leq k \leq 3;\, 1 \leq x \leq 10^{16})

Output

Print TT lines. On line ii, print the answer for the ii-th test case: YES if xx can be made by adding exactly kk 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.

Examples1

  1. Example 1

    Input
    6
    1 3
    1 6
    2 6
    2 12
    3 12
    3 824
    
    Expected output
    YES
    NO
    YES
    NO
    YES
    NO