转圈游戏

转圈游戏

Background

The summer vacation has begun and the day of summer camp has come. On the first night in the dormitory, Xiao A and her new classmates played a circle game in the dormitory.

暑假开始了,夏令营的日子也来临了。住进宿舍的第一天晚上,小A和新认识的同学们在宿舍里玩起了转圈游戏。

Description

The n small partners numbered 0~n-1 form a circle, and their sitting positions are also numbered 0~n-1. Initially, partner no.0 is in position no.0, partner no.1 is in position no.1 ... and so on. The rules of the game are as follows: in each round, the small partner in position 0 goes to position m clockwise, the small partner in position 1 goes to position m+1 .... and so on, the small partner in position nm goes to position 0, the small partner in position n-m+1 goes to position 1 ... the small partner in position n-1 goes to position m-1 clockwise. The game was so fun that little A and his friends played 10^k rounds. May I know where little X friend finally came to?

编号为0~n-1的n个小伙伴围成一圈,他们坐的位置也被编号为了0~n-1。最初,第0号小伙伴在第0号位置,第1号小伙伴在第1号位置......依此类推。
游戏规则如下:每一轮第0号位置上的小伙伴顺时针走到第m号位置,第1号位置小伙伴走到第m+1号位置....依此类推,第n−m号位置上的小伙伴走到第0号位置,第n-m+1 号位置上的小伙伴走到第1号位置......第n-1号位置上的小伙伴顺时针走到第m-1号位置。
这个游戏实在太好玩了,以至于小A和他的小伙伴们玩了10^k轮,请问x号小伙伴最后走到了第几号位置。

Format

Input

The first line has four integers n,m,k,x separated by a single space, meaning as shown in the title.

第一行有四个由单个空格分隔的整数n,m,k,x,意义如题所示。

Output

Only one line and an integer represent the final position number of partner x after 10^k rounds.

仅一行一个整数,表示10^k轮后第x号小伙伴的最终位置编号。

Sample 1

Input

10 3 4 5

Output

5

Limitation

对于30%的数据,0 < k < 7;
对于80%的数据,0 < k < 10^7;
对于100%的数据,1 <n < 1,000,000,0 < m < n,0 ≤ x < n,0 < k < 10^9.

Source

Amorphophallus Orz Group

信息

ID
1022
难度
4
分类
(无)
标签
递交数
7
已通过
2
通过率
29%
上传者

相关

在下列训练计划中:

AOG题库训练计划