Upside-down prime
Time limit3sMemory limit256 MB
Check whether N and its 180-degree rotation are both prime, where digits 3, 4 and 7 make the rotation invalid.
- Level
Medium6 of 10
- Topics
- Number theory, Implementation
- Solved
- No attempts yet
Problem
I knocked my alarm clock over in my sleep, and 08:15 had turned into 51:80. Some digits on a digital display are still digits after you turn them 180 degrees.
Turning a single digit 180 degrees gives this.
- 0, 2, 5 and 8 keep their shape.
- 1 keeps its shape and moves to the other side of its place.
- 6 becomes 9, and 9 becomes 6.
- 3, 4 and 7 turn into shapes that are not digits.
Turning the whole number also reverses the order of the places. Turning 18115211 by 180 degrees gives 11251181. A zero at the front of the result is not read.
The numbers I like are primes. Decide whether is prime and whether the number obtained by turning 180 degrees is prime as well. If contains a 3, a 4 or a 7, the rotation is not a number, so fails the condition.
Input
The first line contains ().
The first digit of is not 0.
Output
Print yes on the first line if is prime and the number obtained by turning it 180 degrees is prime as well. Otherwise print no.