PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000055. Nguyên tố chữ số (Digit Primes)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Nguyên tố chữ số (Digit Primes)

Digit Primes

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer is a digit prime if it is prime and the sum of its decimal digits is also prime. For example, 4141 qualifies because 4141 and 4+1=54+1=5 are prime, whereas 1717 does not because 1+7=81+7=8 is not prime. Given L,RL,R, count digit primes in the inclusive interval [L,R][L,R]. Both endpoints are included.

Input

One line contains the two integers L,RL,R, in that order.

Output

Print one integer: the number of digit primes in [L,R][L,R].

Subtasks

  • Subtask 1 (20 points): 1≤L≤R≤10001\le L\le R\le 1000.
  • Subtask 2 (30 points): 1≤L≤R≤1000001\le L\le R\le 100000.
  • Subtask 3 (50 points): 1≤L≤R≤9999991\le L\le R\le 999999.

Examples

Input

10 100

Output

10

Explanation

The digit primes in [10,100][10,100] are 11,23,29,41,43,47,61,67,83,8911,23,29,41,43,47,61,67,83,89. For instance, 2323 qualifies because 2+3=52+3=5 is prime, while 1717 fails because 1+7=81+7=8 is composite. There are exactly 1010 qualifying numbers, so the answer is 10.