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

#SP0000058. Đếm đoạn có ít nhất K số nguyên tố (Frequent Prime Ranges)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn có ít nhất K số nguyên tố (Frequent Prime Ranges)

Frequent Prime Ranges

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Consider the consecutive integers 2,3,…,N2,3,\ldots,N. A contiguous interval is defined by integer endpoints L,HL,H with 2≤L≤H≤N2\le L\le H\le N. It is K-frequent if it contains at least KK prime numbers. Count the endpoint pairs (L,H)(L,H) that satisfy this condition. Two intervals are distinct if at least one endpoint differs. For K=0K=0, every interval qualifies.

Input

One line contains two integers NN and KK.

Output

Print one integer: the number of qualifying intervals [L,H][L,H].

Subtasks

  • Subtask 1 (20 points): 2≤N≤1002\le N\le 100; 0≤K≤100000\le K\le 10000.
  • Subtask 2 (30 points): 2≤N≤50002\le N\le 5000; 0≤K≤100000\le K\le 10000.
  • Subtask 3 (50 points): 2≤N≤1000002\le N\le 100000; 0≤K≤100000\le K\le 10000.

Examples

Input

5 2

Output

4

Explanation

Between 22 and 55, the primes are 2,3,52,3,5. The intervals containing at least two primes are [2,3][2,3], [2,4][2,4], [2,5][2,5] and [3,5][3,5]. No other interval qualifies, so print 4.