The following a the reason why one should never stay up late at night and do programming contests. I am stuck on this basic question that was is yesterday's COCI. (Paraphrased and restated here, full thing at the bottom for those who want to read it).
There are M items and N people. If they items are divided as equally as possible amongst the N people and someone takes one of the smaller piles, there are then P items left. Given N and P, output the smallest and largest values of M.
A wealthy estate owner is so old that she's at that point in her life when she can't help talking funny.
That is, naturally, the reason why her loving N daughters have started discussing their mother's
heritage.
The youngest is sick and tired of just talking, so she conveniently decided to grab a hold of her share of
the heritage. She knew exactly where her mother keeps her golden medallions – inside a thick sock in
the third drawer next to the mirror in the hallway! The cunning daughter found this pile of medallions,
split it into N equal parts, claimed her part and put the rest back into the sock. If the medallions
couldn't have been split into N identical parts, then the parts were nearly identical: each differed from
another by one medallion at most. In that case, the daughter claimed one of the smaller parts for
herself.
The rest of the daughters found out about this (mis)deed so they counted the remaining medallions and
now they want to know the initial number of medallions inside the sock, before the youngest one took
her share. It is your task to answer this question. Given that there could be more than one possible
answer, output both the smallest and the largest of them.
INPUT
The first line of input contains the integer N (2 ≤ N ≤ 15), the number of daughters.
The second line of input contains the integer O (N ≤ O ≤ 100), the number of remaining medallions.
OUTPUT
The first and only line of output must contain two integers: the minimal and the maximal possible total
number of medallions.
Please help me figure this one out, I know I am going to kick myself when I find out the solution.
I'm not sure how far you've already gotten with this. I thought I'd give it a shot. I think I have the math formulas down, but I stand to be corrected. I'm not sure yet how they're getting multiple solutions with the information that's input. Don't know if this will help, but it's been interesting trying to work it out.
N = number of people (2 <= N <= 15)
O = number of items remaining after one min share is taken out (N < O <= 100) // I see the original problem has N <= O <= 100, but I don't see how the number items remaining could equal the number of people since that would be an equal distribution
M = total number of items
M/N = number of items in a min share (this is what the one daughter took)
M/N + 1 = number of items in a max share
M%N = number of shares with an extra item (M%N != 0)
N - M%N = number of shares without the extra item
One formula ....
Total number of items - one minimum share = number of items remaining or
M - M/N = O Solving for M…
M*(N/N) - M/N = O
(M*(N) - M)/N = O
(M*(N-1))/N = O
M = O*(N/N-1) //O and N are getting input through the program, so M can be calculated. I don't see this giving more than one possible value for M but I could be missing something.
Or a different way at looking it...
Number of items remaining = (number of shares with the max items * number of items in that share) + (number of shares with min items * number of items in that share) or
O = (M%N * (M/N + 1)) + ((N - M%N) * (M/N))
O (or that whole bit above) + M/N = M