Project Euler Problem 190 Solution

Project Euler Problem 190 Solution

Maximising a Weighted Product

by {BetaProjects} | Project Euler & HackerRank
Difficulty: Easy

Project Euler Problem 190 Statement

Let $S_m = (x_1, x_2, \dots , x_m)$ be the $m$-tuple of positive real numbers with $x_1 + x_2 + \cdots + x_m = m$ for which $P_m = x_1 \cdot x_2^2 \cdot \cdots \cdot x_m^m$ is maximised.

For example, it can be verified that $\lfloor P_{10}\rfloor = 4112$ ($\lfloor \, \rfloor$ is the integer part function).

Find $\sum\limits_{m = 2}^{15} \lfloor P_m \rfloor$.

Solution

Python Source Code

from math import prod
s = 0
for m in range(2, 16):
    avg = (m + 1) / 2
    s+= int(prod((k / avg)**k for k in range(1, m + 1)))
print(s)