Difficulty Level: Basic

Submissions: 88 Accuracy:


Balancing Pan

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.

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

Input : 
4 11

Output :

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

Contributor: Mohit Gupta_OMG :)
Author: Mohit Gupta 4

Set Default Code

It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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