#P6485. Minimum Count for Averaging Selection
Minimum Count for Averaging Selection
Minimum Count for Averaging Selection
You are given 5 numbers: \(1,2,3,4,5\). You have an unlimited supply of each. Your task is to select as few numbers as possible such that the average of the chosen numbers equals \(P\). In other words, if you choose \(k\) numbers \(a_1, a_2, \dots, a_k\) (each from the set \(\{1,2,3,4,5\}\)), they must satisfy
[ \frac{a_1+a_2+\cdots+a_k}{k} = P, ]
It is guaranteed that \(1 \le P \le 5\). Note that if \(P\) is one of the numbers \(1,2,3,4,5\), then the answer is \(1\) since you can simply choose \(P\) itself. Otherwise, you need to find the minimum positive integer \(k\) such that \(k \times P\) is an integer (this is equivalent to saying that \(P\) can be represented as a rational number with denominator \(k\) in its simplest form).
inputFormat
The input consists of a single number \(P\) (which can be an integer or a decimal), representing the required average. It is guaranteed that \(1 \le P \le 5\).
outputFormat
Output the minimum count \(k\) of numbers required such that the average of the chosen numbers equals \(P\).
sample
1
1