Panda and Numbers
Practice
4 (18 votes)
Approved
Dynamic programming
Medium
Memoization
Open
Recursion
Problem
51% Success 3667 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Panda is fond of numbers. Given a number, he subtracts it with squares of any one particular digit of that number to get new numbers. This operation can be applied any number of times (possibly zero) till he obtains a pandatic number. If he is able to reach to a pandatic number then he wins. A pandatic number is a number which can be expressed in the form AA, where A is a positive integer.

Input Format:
The first line will contain T, the number of test cases.
Then T lines follow, each containing an integer N.

Output Format:
For each test case, output whether it's possible for panda to reach a pandatic number by doing the operations as described. If it's possible print "Yes" (without quotes), otherwise print "No" (without quotes).

Constraints:

  • Subtask 1: (10 points)
    1 <= T <= 103
    1 <= N <= 103
  • Subtask 2: (90 points)
    1 <= T <= 105
    1 <= N <= 106

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
AlgorithmsDynamic Programming
Points:30
2 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingFenwick TreeMediumSegment TreesSorting
Points:30
573 votes
Tags:
ApprovedDynamic ProgrammingMathMediumOpenReady