#C1749. Circular Primes

    ID: 44988 Type: Default 1000ms 256MiB

Circular Primes

Circular Primes

In this problem, you are required to find all circular primes less than or equal to a given integer n. A number is called a circular prime if all of its rotations are prime. For example, the number 197 is a circular prime because all rotations - \(197\), \(971\), and \(719\) - are prime numbers.

Your task is to write a program that reads an integer from stdin and outputs the count of circular primes as well as the list of these primes in increasing order. The prime check should be based on the standard definition, i.e., a number greater than 1 that has no divisors other than 1 and itself.

Remember to handle the input and output strictly via stdin and stdout respectively.

inputFormat

The input consists of a single integer \(n\) (\(1 \leq n \leq 10^5\)), which represents the upper bound for checking circular primes.

Input is read from stdin.

outputFormat

Output two lines:

  • The first line contains an integer representing the count of circular primes less than or equal to \(n\).
  • The second line contains the circular primes in increasing order, separated by a space. If no circular primes are found, output an empty second line.

Output is written to stdout.

## sample
100
13

2 3 5 7 11 13 17 31 37 71 73 79 97

</p>