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

#SP0000249. Đếm các số P-trơn (P-smooth number)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm các số P-trơn (P-smooth number)

P-smooth number

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer is called PP-smooth if none of its prime factors exceeds PP. By convention, 11 is PP-smooth for every prime PP, as it has no prime factors.

Given a positive integer NN and a prime number P≤100P\le100, count positive integers xx such that 1≤x≤N1\le x\le N and every prime divisor of xx is at most PP.

Print the exact integer answer without taking any modulus.

Input

The only line contains two integers NN and PP. The value PP is guaranteed to be prime.

Output

Print a single integer: the exact number of PP-smooth integers in the interval [1,N][1,N]. No modulus is applied.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1061\le N\le10^6; 2≤P≤972\le P\le97 and PP is prime.
  • Subtask 2 (30 points): 1≤N≤10121\le N\le10^{12}; 2≤P≤972\le P\le97 and PP is prime.
  • Subtask 3 (50 points): 1≤N≤10161\le N\le10^{16}; 2≤P≤972\le P\le97 and PP is prime.

Examples

Input

36 3

Output

14

Explanation

For N=36N=36 and P=3P=3, the only permitted prime factors are 22 and 33. Every counted integer is 2a3b2^a3^b for a,b≥0a,b\ge0. Group by the exponent of 33: b=0b=0 yields 1,2,4,8,16,321,2,4,8,16,32 (six numbers); b=1b=1 yields 3,6,12,243,6,12,24 (four); b=2b=2 yields 9,18,369,18,36 (three); b=3b=3 yields 2727 (one). Higher powers of 33 exceed 3636. Total 6+4+3+1=146+4+3+1=14. The integer 11 is included.