TSECF101 - Editorial

PROBLEM LINK:

Contest

Practice

Author: tseccodecell

DIFFICULTY:

Easy

PROBLEM:

A classroom has N children with roll nos 1 to N. They are reading a story with P paragraphs. Supposing that the teacher starts with any random roll no R, and the students read sequentially what is the roll no of the last child to read?

EXPLANATION:

We need to find the Roll no of last student which can be done by moving P-1 steps further from R.
Roll no of last student: R + P - 1
But since we are moving in a circle so we need to take mod of this summation with N
Because the Roll no starts from 1, so the roll no of the last student =(R -1 + P - 1) % N) + 1

SOLUTIONS:

Solution.