PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000096. Đếm số nguyên tố trong đoạn lớn (Primes in an Interval)
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ố nguyên tố trong đoạn lớn (Primes in an Interval)
Primes in an Interval
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers and , count the prime numbers in the closed interval , including both endpoints. A prime is an integer greater than with exactly two distinct positive divisors, and itself; in particular, is not prime. Output only the number of primes, not the list.
The endpoints may coincide. In that case the answer is if the only number is prime, and otherwise.
Input
One line contains two integers and , the inclusive left and right endpoints of the interval.
Output
Print one integer: the number of primes in the interval.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
21 40
Output
4
Explanation
The primes in are . Every other number in the interval has a nontrivial divisor, so the count is .