The Beauty of Cycles

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

We say a base-kk real number is beautiful if the decimal part of the real number is purely cyclic.

Now we want to know given base-10 numbers n,mn,m, how many distinct (in value) purely cyclic real numbers there are that can be represented by xy\frac{x}{y} where 1xn,1ym1 \leq x \leq n, 1 \leq y \leq m, and x,yx,y are integers.

A real number is said to be purely cyclic if and only if it can be written in the form of a.c_1˙c_2c_3c_p1c_p˙\displaystyle \displaystyle a.\dot{c\_1} c\_2 c\_3 \ldots c\_{p-1} \dot{c\_p} where aa is an (base-kk) integer, p1p \geq 1, and for 1ip1 \leq i \leq p, c_ic\_i is a digit in base kk.

For example, under base 10, 0.45454545=0.4˙5˙\displaystyle 0.45454545\cdots = 0.\dot{4}\dot{5} is purely cyclic and can be represented by 511\frac{5}{11} or 1022\frac{10}{22}. Under base 10, 0.166666=0.16˙\displaystyle 0.166666\cdots = 0.1\dot{6} is not purely cyclic but can be represented by fractions like 16\frac{1}{6}.

Attention: an integer is purely cyclic since its decimal part can be written as repeating 0s or repeating k1k-1s. A terminating decimal whose decimal part is non-zero is not considered to be purely cyclic.

Notes: In China, the repeating part of a repeating decimal is marked by one or two dots. In some countries, the repeating part is marked by a line above the repeating part.

입력

The input consists of one line with three base-10 integers n,m,kn,m,k whose meanings are described in the problem description.

출력

Output a line with an integer denoting the beautiful numbers satisfying all the constraints.

제한

For all test cases, 1n109,1m109,2k20001 \leq n \leq 10^9, 1 \leq m \leq 10^9, 2 \leq k \leq 2000.