Palindromic Primes#1217

Palindromic Primes

1 second
64 megabytes
Medium

Prime numbers are defined as follows: a number is prime if it is greater than and divisible without remainder only by itself and . Note that by definition, neither zero nor one are prime numbers.

A palindromic number is a number whose representation in the given positional numeral system is a palindrome, i.e., a string that reads the same left to right and right to left.

Write a program that finds palindromic prime numbers for a given number of digits and numeral system.

Input

The input file contains a series of pairs of numbers (separated by spaces), each of which specifies a separate task, and ends with a pair of zeros. The first number indicates the number of digits for the numbers considered, the second number is the base in which the numbers should be generated. The numbers are separated by a single space. It is guaranteed that all palindromic prime numbers for this task can be represented within a standard -bit signed integer. Valid bases are integers from to ; bases above ten are handled as extensions of hexadecimal. This means that valid digits are characters from and .

Output

For each task, output one line indicating the number of digits and the base, and the next line—the number of palindromic prime numbers found, as shown in the sample output. Each such pair in the output should be separated by an empty line.

Examples

Example 1

Loading
Loading