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
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đế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 . For example, is a digit megaprime, whereas is composite and contains the forbidden digit .
Given two positive integers and , count the digit megaprimes in the inclusive interval .
Input
One line contains two integers and , the inclusive lower and upper bounds, in that order.
Output
Print one integer: the number of digit megaprimes in .
Subtasks
- Subtask 1 (20 points): and .
- Subtask 2 (30 points): and .
- Subtask 3 (50 points): and .
Examples
Example 1
Input
1 100
Output
8
Explanation
In , the qualifying numbers are . Therefore the answer is .
Example 2
Input
20 30
Output
1
Explanation
Among the integers from through , only satisfies both conditions, so the answer is .