A. Primes or Palindromes?
time limit per test
memory limit per test
input
output
Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!
prime
palindromic
π(n) — the number of primes no larger than n, rub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.
A find the maximum n, such that π(n) ≤ A·rub(n).
Input
p, q, the numerator and denominator of the fraction that is the value of A (
,
).
Output
"Palindromic tree is better than splay tree"
Sample test(s)
input
1 1
output
40
input
1 42
output
1
input
6 4
output
172
可以发现不可能无解,极限情况n不大