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

#SP0000213. Đếm ước giai thừa chia hết cho D (Divisibility of Factors)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm ước giai thừa chia hết cho D (Divisibility of Factors)

Divisibility of Factors

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers NN and DD, with D≠0D\ne0, count the positive integers xx satisfying both conditions:

  • xx divides N!N!;
  • xx is divisible by DD.

We use 0!=10!=1. Divisibility by a negative integer has its usual meaning: DD divides xx exactly when ∣D∣|D| divides xx. Distinct divisor values are counted separately.

Input

The only line contains the integers N,DN,D.

Output

Print the number of distinct positive divisors of N!N! divisible by DD, or 0 if there are none.

Subtasks

  • Subtask 1 (20 points): 0≤N≤300\le N\le 30; 1≤∣D∣≤1001\le |D|\le 100.
  • Subtask 2 (30 points): 0≤N≤650\le N\le 65; 1≤∣D∣≤1061\le |D|\le 10^6.
  • Subtask 3 (50 points): 0≤N≤1000\le N\le 100; 1≤∣D∣≤231−11\le |D|\le 2^{31}-1.

Examples

Input

10 2

Output

240

Explanation

10!=28⋅34⋅52⋅710!=2^8\cdot3^4\cdot5^2\cdot7. A divisor divisible by 22 must have exponent of 22 between 11 and 88 (eight choices). The exponents of 3,5,73,5,7 admit 5,3,25,3,2 choices, respectively. Thus 8⋅5⋅3⋅2=2408\cdot5\cdot3\cdot2=240 divisors qualify.