Remarkable Primes

Interview

Time limit2sMemory limit4 MB

Summary
Given N, output all N-digit primes whose every left-hand prefix (1 to N digits) is also prime, in ascending order.
Level

Medium4 of 10

Topics
Backtracking, Math, Number theory
Solved
No attempts yet

Problem

Subin loves prime numbers and enjoys exploring them. Recently, one number caught her attention: 7331.

The number 7331 is prime. More surprisingly, 733, 73, and 7 are also prime. In other words, every prefix formed by taking the first 1, 2, 3, and 4 digits from the left is prime. Subin calls such a number a remarkable prime.

Given N, find every N-digit remarkable prime.

Input

The first line contains an integer N (1 ≤ N ≤ 8).

Output

Print all N-digit remarkable primes in ascending order, one per line.

Examples1

  1. Example 1

    Input
    4
    
    Expected output
    2333
    2339
    2393
    2399
    2939
    3119
    3137
    3733
    3739
    3793
    3797
    5939
    7193
    7331
    7333
    7393