Sum of Powers of 3

5

1 votes
Problem

In this problem you have to answer  queries. In each query you are given two integers  and . You have to decide if it is possible to represent  as the sum of exactly  powers of 3 (they may or may not be distinct). If it is possible to represent  in such a way then the answer for that query is "YES"(without quotes) otherwise it is a "NO" (without quotes).

Input Format

The first line contains a postive integer  - the number of queries. 

Each of the next  lines contains two space separated integers  and  .

Constraints

Output Format

For each query, print the answer to that query i.e. "YES"(without quotes) if it is possible to write  as the sum of exactly  powers of 3 else print "NO"(without quotes).

 

Sample Input
2
100 1
100 6
Sample Output
NO
YES
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?