Question Description |
There are n small partners (numbered from 0 to n-1) to sit around and play games. The n positions are numbered in a clockwise direction, from 0 to n-1. Initially, the No. 0 partner at position No. 0, the 1th small partner in the 1th position, ..., and so on. The rules of the game are as follows: each round of the No. 0 position of the small partner clockwise to the location of position m, the 1th position of the small partner to the location of position m+1, ..., and so on, the location of the small partner in position n−m to the No. 0 position, the n-m+1 position of the small partners to the 1th position, ... The small partner in position n-1 clockwise to position m-1. Now, altogether has carried on the 10^k round, ask the X small partner finally reached the number of the first place. |
Input |
Enter a total of 1 rows, containing 4 integers n, m, K, X, separated by a space between each of the two integers. |
Output |
Outputs a total of 1 rows, containing 1 integers representing the position number of the X-10^k after the wheel. |
Input example |
10 3 4 5 |
Output example |
5 |
Other Notes |
Data range: 0<n<10^6,0<m<n,0<x<=n,0<k<10^9 |
Fast power water and water
AC Code:
#include <iostream>using namespacestd;intmod,m,k,x;intFacintAintBB) { intret=1; while(b) {if(b&1) (Ret*=a)%=MoD; (A*=a)%=MoD; b/=2; } returnret;}intMain () {scanf ("%d%d%d%d",&mod,&m,&k,&x); cout<< (x+ (M*FAC (Ten, k))%mod+mod)%MoD;}
View Code
NOIP201305 Circles Game