Find whole numbers of which's average is given

34 Views Asked by At

I was trying to calculate something, when I came across with something I couldn't solve. I needed to "reverse an average", find whole numbers, of which's average is 0,625. I feel like this is a thing that must be brute forced, check every possible combination. What would the most effective way to write an algorithm that performs a reverse average search?

1

There are 1 best solutions below

0
On

$0.625 = \frac58$ so you need $8k$ integers which add up to $5k$ for some positive integer $k$ to get this exactly

$\{0,0,0,0,0,0,0,5\}$ is a simple example, as is $\{0,0,0,1,1,1,1,1\}$, but there are many more