#P1925. Maximal Partition Product and Finite Decimal Determination

    ID: 15207 Type: Default 1000ms 256MiB

Maximal Partition Product and Finite Decimal Determination

Maximal Partition Product and Finite Decimal Determination

Given a positive integer \(n\), we consider partitioning \(n\) into \(k\) equal parts, each of which is \(r = \frac{n}{k}\). Define the product

\[ p = r \times r \times \cdots \times r = r^k = \left(\frac{n}{k}\right)^k \]

for that partition.

Let \(M(n)\) be the maximum value of \(p\) when \(k\) ranges over the positive integers \(1 \le k \le n\). For example, when \(n=11\), the maximum is achieved at \(k=4\) with

\[M(11)=\left(\frac{11}{4}\right)^4=\frac{14641}{256} \approx 57.19140625,\]

and when \(n=8\), the maximum is obtained at \(k=3\):

\[M(8)=\left(\frac{8}{3}\right)^3=\frac{512}{27} \approx 18.96296296. \]

A rational number in its lowest terms has a terminating (finite) decimal expansion if and only if its denominator has no prime factors other than \(2\) and \(5\). For the value \(M(n)\), write it as a reduced fraction. Let \(D(n)\) be defined as follows:

  • If \(M(n)\) is a non-terminating (infinite) decimal, then \(D(n)=n\).
  • If \(M(n)\) is a terminating (finite) decimal, then \(D(n)=-n\).

Your task is to compute the sum

[ S = D(5) + D(6) + \cdots + D(a), ]

for a given integer \(a (a\ge5)\).

inputFormat

The input contains one integer \(a\) (with \(a \ge 5\)) on a single line.

outputFormat

Output the value of \(D(5)+D(6)+\cdots+D(a)\) on a single line.

sample

5
-5