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

#SP0000266. Đếm số siêu nguyên tố theo chữ số (Megaprime Numbers)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm số siêu nguyên tố theo chữ số (Megaprime Numbers)

Megaprime Numbers

Source: HackerRank

Version: Phuoc Hung OJ Extended

Problem Statement

A digit megaprime is a positive integer that is prime and whose every decimal digit belongs to {2,3,5,7}\{2,3,5,7\}. For example, 2323 is a digit megaprime, whereas 3535 is composite and 1313 contains the forbidden digit 11.

Given two positive integers LL and RR, count the digit megaprimes in the inclusive interval [L,R][L,R].

Input

One line contains two integers LL and RR, the inclusive lower and upper bounds, in that order.

Output

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

Subtasks

  • Subtask 1 (20 points): 1≤L≤R≤1051\le L\le R\le 10^5 and R−L≤1000R-L\le 1000.
  • Subtask 2 (30 points): 1≤L≤R≤1091\le L\le R\le 10^9 and R−L≤106R-L\le 10^6.
  • Subtask 3 (50 points): 1≤L≤R≤10151\le L\le R\le 10^{15} and R−L≤107R-L\le 10^7.

Examples

Example 1

Input

1 100

Output

8

Explanation

In [1,100][1,100], the qualifying numbers are 2,3,5,7,23,37,53,732,3,5,7,23,37,53,73. Therefore the answer is 88.

Example 2

Input

20 30

Output

1

Explanation

Among the integers from 2020 through 3030, only 2323 satisfies both conditions, so the answer is 11.