The Beauty of Cycles
Time limit2sMemory limit1024 MB
Given n, m, and base k, count the distinct purely cyclic base-k reals that can be written as x/y with 1 <= x <= n and 1 <= y <= m.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
We say a base- real number is beautiful if its decimal part is purely cyclic.
Given base-10 integers and , count the distinct (in value) purely cyclic real numbers that can be written as , where and are integers with and .
A real number is purely cyclic if and only if it can be written in the form where is a base- integer, , and for each , is a base- digit.
For example, in base 10, is purely cyclic and can be represented by or . In base 10, is not purely cyclic, but it can be represented by fractions such as .
Attention: an integer is purely cyclic, since its decimal part can be written as repeating 0s or repeating s. A terminating decimal with a nonzero decimal part is not purely cyclic.
In China, the repeating part is marked by one or two dots. In some countries, it is marked by a line above the repeating part.
Input
The input is one line with three base-10 integers , , and . Their meanings are described in the problem statement.
Output
Print one line with the number of beautiful numbers that satisfy all the constraints.
Constraints
For all test cases, , , and .