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

#GL0000388. Phân hoạch nghệ thuật (Artistic Partition)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân hoạch nghệ thuật (Artistic Partition)

Artistic Partition

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

For positive integers l≤rl\le r, let c(l,r)c(l,r) be the number of integer pairs (i,j)(i,j) such that

l≤i≤j≤r,gcd⁡(i,j)≥l.l\le i\le j\le r,\qquad\gcd(i,j)\ge l.

Given integers n,kn,k with 1≤k≤n1\le k\le n, partition the integers 1,2,…,n1,2,\ldots,n into exactly kk non-empty consecutive segments covering all nn values. If the segments are [l1,r1],…,[lk,rk][l_1,r_1],\ldots,[l_k,r_k], minimize

c(l1,r1)+c(l2,r2)+⋯+c(lk,rk).c(l_1,r_1)+c(l_2,r_2)+\cdots+c(l_k,r_k).

Equivalently, choose 0=x1<x2<⋯<xk+1=n0=x_1<x_2<\cdots<x_{k+1}=n and use segments [xi+1,xi+1][x_i+1,x_{i+1}].

PHOJ convention: Each input file contains one pair (n,k)(n,k) and no leading test count tt.

Input

A line containing n,kn,k.

Output

The minimum possible sum of segment costs.

Subtasks

  • Subtask 1 (20 points): 1≤k≤n≤201\le k\le n\le20.

  • Subtask 2 (30 points): 1≤k≤n≤2 0001\le k\le n\le2\,000.

  • Subtask 3 (50 points): 1≤k≤n≤100 0001\le k\le n\le100\,000.

Examples

Example 1

Input

6 2

Output

8

Explanation

The two segments [1,2][1,2] and [3,6][3,6] have costs 33 and 55 respectively, for a minimum sum of 88. The five valid pairs in [3,6][3,6] are (3,3),(4,4),(5,5),(6,6),(3,6)(3,3),(4,4),(5,5),(6,6),(3,6).

Example 2

Input

4 4

Output

4

Explanation

Every segment must be a singleton and contributes exactly one pair.

Example 3

Input

10 3

Output

11

Explanation

One optimal partition is [1,1],[2,5],[6,10][1,1],[2,5],[6,10], with costs 1,5,51,5,5, respectively.