GlobeX Cup '18 J3 - Good Numbers

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Jonathan is writing a problem for the GlobeX Canada Cup. However, he lost his ideas for the first 3 problems of the junior division. So, Jonathan is making a problem about the numbers he loves the most: prime numbers. A good number is defined as an integer such that it is prime, and the sum of its digits is also prime. A number p is prime if it only has two divisors, 1 and itself (p).

Given a list of N integers, find out how many of them are good numbers.

Input Specification

The first line will contain the integer N (1 \le N \le 5\,000), the number of integers to test.

The next N lines will each contain an integer, x (1 \le x \le 10^5), the integer to test.

Output Specification

On the first line, output one integer, the number of good numbers in the list.


Subtask 1 [30%]

x \le 100

Subtask 2 [70%]

No further constraints.

Sample Input


Sample Output



There are no comments at the moment.