当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5158:Have meal

题目描述
I have been in school for several years, so I have visited all messes here. Now I have lost intersts in all of the foods. So when during the meal time, I don’t know which mess I should go to. So I came up with a solution.
There are 4 messes in our school, I number them from 0 to 3. Then I says “Big Bing Small Jiang, Point Who Is Who!”, when I say the first word I point to the mess which is numbered 0, when I say the i-th (i>1) word I point to the mess whose number is one larger than the previous one. In case of the number of previous mess is 3, I will point to 0 again. I will go to the mess which I point to last time. Thus in this case I will go to the mess which is numbered 3. The following table explains the course of my solution to this case.
$\begin{array} {|c|c|c|c|}
\hline
\quad \text{ Word I say} \quad &\quad \text{ Big} \quad &\quad \text{ Bing} \quad &\quad \text{ Small} \quad &\quad \text{ Jiang} \quad &\quad \text{ Point} \quad &\quad \text{ Who} \quad &\quad \text{ Is} \quad &\quad \text{ Who} \quad\\
\hline
\hline
\quad \text{ Mess id I point to} \quad &\quad \text{ 0} \quad &\quad \text{ 1} \quad &\quad \text{ 2} \quad &\quad \text{ 3} \quad &\quad \text{ 0} \quad &\quad \text{ 1} \quad &\quad \text{ 2} \quad &\quad \text{ 3} \quad\\
\hline

\end{array}\\
$
I will go to university after several days, I have heard that there are so many messes in it. So I will apply my solution again. Surpose there are n messes which are numberd through 0 to n-1, and I will say m words. When I say the first word I point to the mess which is numbered 0, when I say the i-th (i>1) word I point to the mess whose number is one larger than the previous one. In case of the number of previous mess is n-1, I will point to 0 again. I will go to the mess which I point to last time. So which mess will I point to?.
It is so time-consuming to count it through manual work. So I want you to write a program to help me. Would you help me?
输入解释
Multi test cases (about 10000), every case contain two integers n and m in a single line.

[Technical Specification]
1<=n, m<=100
输出解释
For each case, output the number of the mess which I should go to.
输入样例
4 3
1 100
输出样例
2
0
来自杭电HDUOJ的附加信息
Recommend heyang

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #26

源链接: HDU-5158

最后修改于 2020-10-25T23:20:17+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)