Balancing Pan
##### Submissions: 122   Accuracy: 16.38%   Difficulty: Easy   Marks: 2

Given a simple weighting scale with two pans, we are given a weight T and some other weights which are the powers of a specific number a, our goal is to balance these pans using the given weights. More formally we need to satisfy this equation,T + (some power of a) = (some other powers of a).
Remember that we are given exactly one weight corresponding to one power.

```Examples:
Input  : T = 11    and  a = 4
Then scale can be balanced as,
11 + 4 + 1 = 16
Output  : YES, pans can be balanced```

Input :
The first line of input contains an integer Test denoting the Test cases. Then Test test cases follow. Second line contains value of T and a.

Output :
Yes, if pans can be balanced; else NO

Constraints :
1 ≤ Test ≤ 50
1 ≤ a ≤ T ≤ 1000

Examples:
Input :

1
4 11

Output :
YES

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Mohit Gupta_OMG :)
Author: Mohit Gupta 4

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.