LA - It's All About Three

Consider the series of numbers whose all prime factors have 3 as their least (right-most) digit. For example, the first 10 numbers in this series are: 3 9 13 23 27 39 43 53 69 73 The numbers 3, 13, 23, 43, 53, and 73 are in this series since they’re all primes whose least digit is a 3. Whereas 9 (3 * 3,) 27 (3 * 3 * 3,) 39 (3 * 13,) and 69 (23 * 3) are in since all their prime factors have a 3 as their least digit. Write a program that takes a list of positive integers and determines if each integer is in this series or not.

Input
The input file contains a list of one or more positive integers, each given on a separate line. Each integer is less than a million. The last line of the file contains a -1 (which is not part of the list.)

Output
For each number in the input, write, on a separate line, the number itself followed by the word "YES" if the number is in the series described above, or "NO" if it isn’t. Separate the number from the answer by a single space.

Analyses

 * View problem analysis (written by Mido1236)

Solutions
If you solve this problem, please provide a link to your solution here.