NOI '16 P3 - The Beauty of Cycles

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem type

We say a base-k 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,m, how many distinct (in value) purely cyclic real numbers there are that can be represented by xy where 1xn, 1ym, and x,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.c1˙c2c3cp1cp˙ where a is an (base-k) integer, p1, and for 1ip, ci is a digit in base k.

For example, under base 10, 0.45454545=0.4˙5˙ is purely cyclic and can be represented by 511 or 1022. Under base 10, 0.166666=0.16˙ is not purely cyclic but can be represented by fractions like 16.

Attention: an integer is purely cyclic since its decimal part can be written as repeating 0s or repeating k1s. 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.

Input Specification

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

Output Specification

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

Sample Input 1

Copy
2 6 10

Sample Output 1

Copy
4

Explanation of Sample 1

The beautiful numbers are 1/1=1.0000, 1/3=0.3333, 2/1=2.0000, 2/3=0.6666. Even though 1/1 and 2/2 are both purely cyclic, they are equal in value so they are only counted once. Similarly, 1/3 and 2/6 should also be counted once.

Sample Input 2

Copy
23333 666666 310

Sample Output 2

Copy
5089564081

Constraints

For all test cases, 1n109, 1m109, 2k2000.

Items left blank means there are no special restrictions.

Test casenmk
11020=2
2100104
31000
410000
51020=3
6100104
71000
810000
91020100
10100104
1110001000
1210000
13105108100
142×1051000
155×105
16106108100
172×1061000
185×106
19107108100
202×1071000
21
22,23108108
24,25

Comments

There are no comments at the moment.