21 5 s 128 MB
Little Olaf has two piggy banks. Every day he puts one Euro in one of the banks until each bank contains N Euros. Then he can buy a new toy.
Little Olaf also likes prime numbers. Sometimes, the amount of Euros in the ﬁrst bank concatenated with the amount of Euros in the second bank is a prime number. For example, if the ﬁrst bank contains
12 Euros and the second bank contains 7 Euros, the concatenation 127 is a prime number.
Your task is to ﬁnd an optimal order to put the Euros in the banks so that as many prime numbers as
possible appear. Initially, each bank contains 1 Euro.
Here is one order to ﬁll the banks when N = 4:
Only one prime number appears: 43. The following order is much better:
Now three prime numbers appear: 31, 41, and 43. This is an optimal ﬁlling order for N = 4.
Note that the initial 11 is not counted!
The only line of input contains one integer N: the number of Euros that each piggy bank should ﬁnally contain(1≤N≤999).
The only line of output should contain one integer: the number of prime numbers in an optimal filling order.