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.
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 ; for example, from to . For each such potential we check whether it is a possible solution. How? The youngest daughter would take medallions, which means there are medallions remaining. If that number equals the actual remainder , 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: stands for integer division.
Comments