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

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

1 lộ trình

Đế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 LL and RR, count the prime numbers in the closed interval [L,R][L,R], including both endpoints. A prime is an integer greater than 11 with exactly two distinct positive divisors, 11 and itself; in particular, 11 is not prime. Output only the number of primes, not the list.

The endpoints may coincide. In that case the answer is 11 if the only number is prime, and 00 otherwise.

Input

One line contains two integers LL and RR, 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): 1≤L≤R≤100001\le L\le R\le 10000; R−L≤2000R-L\le 2000.
  • Subtask 2 (30 points): 1≤L≤R≤1000000001\le L\le R\le 100000000; R−L≤50000R-L\le 50000.
  • Subtask 3 (50 points): 1≤L≤R≤10000000000001\le L\le R\le 1000000000000; R−L≤500000R-L\le 500000.

Examples

Input

21 40

Output

4

Explanation

The primes in [21,40][21,40] are 23,29,31,3723,29,31,37. Every other number in the interval has a nontrivial divisor, so the count is 44.