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

#SP0000095. Mặt nạ nguyên tố (Prime Mask)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mặt nạ nguyên tố (Prime Mask)

Prime Mask

Source: LQDOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Consider a positive integer nn. Let p1,p2,…,pkp_1,p_2,\ldots,p_k denote the distinct prime divisors of nn, listing each prime divisor exactly once. Define:

S=p1+p2+⋯+pk,P=p1p2⋯pk.S=p_1+p_2+\cdots+p_k,\qquad P=p_1p_2\cdots p_k.

The number nn is valid if and only if all three conditions hold:

  • k≥2k\ge2: nn has at least two distinct prime divisors.
  • PP is divisible by SS.
  • The quotient Q=P/SQ=P/S is a prime number.

The exponents in the prime factorization of nn do not change SS or PP: each distinct prime divisor is counted exactly once.

Given two integers L,RL,R, count the valid integers nn in the inclusive range L≤n≤RL\le n\le R.

Input

A single line containing two integers LL and RR, the endpoints of the query interval.

Output

Print one integer: the number of valid numbers in the inclusive interval [L,R][L,R].

Subtasks

  • Subtask 1 (50 points): 1≤L≤R≤1051\le L\le R\le10^5.
  • Subtask 2 (50 points): 1≤L≤R≤5⋅1061\le L\le R\le5\cdot10^6.

Examples

Example 1

Input

1 30

Output

1

Explanation

In [1,30][1,30], 30=2⋅3⋅530=2\cdot3\cdot5 has distinct prime divisors 2,3,52,3,5. Thus S=2+3+5=10S=2+3+5=10, P=2⋅3⋅5=30P=2\cdot3\cdot5=30, and Q=30/10=3Q=30/10=3, which is prime. No other number in the interval satisfies all three conditions, so the answer is 11.

Example 2

Input

30 30

Output

1

Explanation

The interval contains only the number 3030. As verified in Example 1, it meets all three conditions, hence the answer is 11.

Example 3

Input

1 1000

Output

40

Explanation

For 3030, P=30P=30, S=10S=10, and P/S=3P/S=3 is prime. The number 60=22⋅3⋅560=2^2\cdot3\cdot5 has the same distinct prime divisors {2,3,5}\{2,3,5\}, so S=10S=10, P=30P=30, and P/S=3P/S=3: it is also valid. For 70=2⋅5⋅770=2\cdot5\cdot7, we get S=14S=14, P=70P=70, and P/S=5P/S=5, which is prime.

Checking the remaining integers similarly, the complete list of valid values in the interval is:

30 60 70 90 105 120 140 150 180 231
240 270 280 286 300 315 350 360 450 480
490 525 540 560 572 600 627 646 693 700
720 735 750 805 810 897 900 945 960 980

There are exactly 4040 values in the list, so the output is 40.