Editorial for COCI '13 Contest 4 #1 Nasljedstvo


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

It is possible to solve this task "mathematically", by testing out certain cases. We leave the proof of this procedure as a practice for the reader and continue to explain a simpler solution.

We use a for loop to go through all possible values of the initial number of medallions M; for example, from 1 to 1000. For each such potential M we check whether it is a possible solution. How? The youngest daughter would take M \mathbin{div} N medallions, which means there are M - M \mathbin{div} N medallions remaining. If that number equals the actual remainder O, we have found ourselves a solution. Additionally, we have to keep track of the smallest and biggest solution in two variables; we are going to output them in the end.

Please note: div stands for integer division.


Comments

There are no comments at the moment.