#K74852. Find Next Prime with Prime Digits

    ID: 34289 Type: Default 1000ms 256MiB

Find Next Prime with Prime Digits

Find Next Prime with Prime Digits

You are given a positive integer \(N\). Your task is to find the smallest prime number strictly greater than \(N\) which is composed exclusively of prime digits, i.e. the digits \(2\), \(3\), \(5\), and \(7\). For example, if \(N=10\), the answer is \(23\) because 23 is prime and both of its digits (2 and 3) are prime digits.

The problem requires you to implement an algorithm that checks for primality and verifies that all digits of a number belong to the set \(\{2, 3, 5, 7\}\). You must then iterate over integers greater than \(N\) until you find one satisfying both conditions.

Examples:

  • Input: 10, Output: 23
  • Input: 30, Output: 37

inputFormat

The input consists of a single integer \(N\) provided via standard input (stdin).

outputFormat

Output a single integer which is the smallest prime number greater than \(N\) and composed only of the digits \(2\), \(3\), \(5\), and \(7\). The result should be printed to standard output (stdout).

## sample
10
23