PROBLEM LINK:
Practice
Author: Rupanjan Hari
Tester: Rupanjan Hari
DIFFICULTY
: Easy
PREREQUISITES
: Math
QUICK EXPLANATION
Say there are N=5 prisoners and M=2 sweets. Distribution starts at ID number S=1, so prisoner 1 gets the first sweet and prisoner 2 gets the second (last) sweet. Thus, we must warn prisoner 2 about the poison, so we print 2 on a new line.
EXPLANATION
A simple formula drives the whole problem to the right direction by decreasing the complexity of the program to O(n) i.e. final=(S+(M%N)-1)%N; where the letters have their significance as per problem.
This formula has to be applied for each input series.
SOLUTION:
click here to see the solution