#P6583. Finite Decimal Representations Count
Finite Decimal Representations Count
Finite Decimal Representations Count
Given a positive integer n, count the number of ordered pairs of integers (x, y) with 1 ≤ x, y ≤ n such that the fraction \(\frac{x}{y}\) has a finite decimal representation.
A rational number \(\frac{x}{y}\) in its lowest terms (where \(x\) and \(y\) are coprime) can be represented as a finite decimal if and only if the denominator has no prime factors other than 2 and 5. Equivalently, if \(d = \gcd(x,y)\) and the reduced fraction becomes \(\frac{x/d}{y/d}\), then \(\frac{x}{y}\) is finitely representable in base 10 if and only if every prime factor of \(y/d\) is either 2 or 5.
It can be shown that this condition is equivalent to requiring that F(y) divides \(x\), where F(y) is defined as the part of \(y\) that is not divisible by 2 or 5. Formally, for each integer \(y\), remove all factors of 2 and 5 to obtain \(F(y)\). Then, \(\frac{x}{y}\) can be expressed as a finite decimal if and only if \(F(y)\) divides \(x\).
Your task is to compute the total number of pairs \((x, y)\) for which the above condition holds.
inputFormat
The input consists of a single positive integer n (1 ≤ n). It is provided on one line.
outputFormat
Output a single integer – the number of ordered pairs \((x, y)\) satisfying the condition.
sample
1
1