#P1925. 最大划分乘积

最大划分乘积

题目背景

欧拉工程183题 有改动

题目描述

Let NN be a positive integer and let NN be split into kk equal parts, r=N/kr = N/k, so that N=r+r+...+rN = r + r + ... + r.

Let PP be the product of these parts, P=r×r×...×r=rkP = r ×r × ... × r = rk.

For example, if 1111 is split into five equal parts, 11=2.2+2.2+2.2+2.2+2.211 = 2.2 + 2.2 + 2.2 + 2.2 + 2.2, then P=2.25=51.53632P = 2.2^5 = 51.53632.

Let M(N)=PmaxM(N) = P_{\max} for a given value of NN.

It turns out that the maximum for N=11N = 11 is found by splitting eleven into four equal parts which leads to Pmax=(11/4)4P_{max} = (11/4)^4; that is, M(11)=14641/256=57.19140625M(11) = 14641/256 = 57.19140625, which is a terminating decimal.

However, for N=8N = 8 the maximum is achieved by splitting it into three equal parts, so M(8)=512/27M(8) = 512/27, which is a non-terminating decimal.

Let D(N)=ND(N) = N if M(N)M(N) is a non-terminating decimal and D(N)=ND(N) = -N if M(N)M(N) is a terminating decimal.

输入格式

输入文件仅一行为正整数 a(5a32767)a(5≤a≤32767).

输出格式

输出文件仅一行 为 D(5)+D(6)+...+D(a)D(5)+D(6)+...+D(a) 的值.

题目大意

将正整数 nn 分为 kk 个相等的部分 rr,有 r=n/kr=n/k

p=r×r×...×r=rkp=r×r×...×r=r^k(共有 kkrr)。例如,将 1111 分为五等份,则 p=2.25p=2.2^5

M(n)M(n) 为满足要求的对应 nn 的最大的 pp

n=11n=11 时,M(n)=14641/256=57.19140625M(n)=14641/256=57.19140625,是有限小数;当 n=8n=8 时,M(n)=512/27M(n)=512/27,是无限小数。

若当 M(n)M(n) 为无限小数时,D(n)=nD(n)=n,否则 D(n)=nD(n)=-n,求 D(5)+D(6)++D(a)D(5)+D(6)+\dots +D(a) 的值。

输入文件仅一行,为正整数 a(5a32767)a(5 \le a \le 32767)

输出文件仅一行,表示 D(5)+D(6)++D(a)D(5)+D(6)+\dots +D(a) 的值。

10
-15
100
2438