Random Number Check
Time limit1sMemory limit64 MB
For each of N numbers decide whether no digit repeats four times in a row and every divisor greater than 1 exceeds K.
- Level
Medium4 of 10
- Topics
- Math, Number theory, String, Brute force
- Solved
- No attempts yet
Problem
Mr. Random supplies random numbers to the people who come to him. Producing a large amount of random numbers by hand is hard, so he decided to use a random number generator.
The generator produces a few million numbers per second. Some of the numbers it produces do not look random to Mr. Random, so he has to filter every generated number.
A number is random when it satisfies both of the following conditions.
- No digit appears more than 3 times in a row.
- Every divisor of the number other than 1 is greater than .
For example, when is 2, the numbers 1112233445, 111333555 and 111 are random. The number 122221 is not random because the digit 2 appears 4 times in a row, and 1234 is not random because 2 divides 1234 and 2 is not greater than .
The number 1 has no divisor other than 1, so it satisfies the second condition.
Write a program that decides whether a number is random.
Input
The first line contains two integers and . (, )
Each of the next lines contains one positive integer. Every given positive integer is smaller than .
Output
Print lines. On each line print YES if the corresponding number is random, and NO otherwise.
Hint
In the sample, is 5.
- 3 is not random because the divisor 3 is not greater than .
- 10 is not random because the divisors 2 and 5 are not greater than .
- 7 is random because the divisor 7 is greater than and no digit appears twice in a row.
- 7777 is not random because the digit 7 appears 4 times in a row.
- 121 is random because the divisors 11 and 121 are both greater than .