Moody Numbers
Practice
3 (10 votes)
Approved
Brute Force search
Math
Medium
Open
Problem
22% Success 5223 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Some people are just moody, you just cannot reason with them. Same goes with Natural Numbers. Some of them ultimely want to become 1 or 4 and will evolve infinite times if they have to, to become what they want to. To evolve, they use a function F such that N = F(N). Function F(N) is defined as :

F(N) = sum_of_digits(N 2)

So, your task is that given a number N, output if it is possible for it to ultimately become {1 or 4} or not.

Input:

First line contains T which is the number of test cases.
T lines follow each with an integer N.

Output:

For each N output "YES" or "NO" if the number can achieve desired goal or not.

Constraints:

  • 1 ≤ T ≤ 106
  • 1≤ N ≤ 109

Scoring:

  • 1 ≤ T ≤ 106,1 ≤ N ≤ 103:(30 pts)
  • 1 ≤ T ≤ 106,1 ≤ N ≤ 106:(30 pts)
  • 1 ≤ T ≤ 106,1 ≤ N ≤ 109:(40 pts)

Note:

Large IO. Use scanf/printf(in C/C++).

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
18 votes
Tags:
ApprovedDynamic ProgrammingMediumMemoizationOpenRecursion
Points:30
7 votes
Tags:
Ad-HocApprovedBasic ProgrammingBrute ForceDynamic ProgrammingMediumOpenSieve
Points:30
34 votes
Tags:
Basic ProgrammingMediumReady