Reprint please indicate source from CSDN user Ametake
Topics from NOIP2013TGD1T1
Title Description
Description
N Small partners (numbered from 0 to n-1) sit around and play the game. 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 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 go to the 1th position, ..., the n-1 Position of the small partner, 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.
Enter a description input
Description
Enter a total of 1 rows, containing 4 integers n, m, K, X, separated by a space between each of the two integers.
outputs description output
Description
Outputs a total of 1 rows, containing 1 integers representing the position number of the X-10^k after the wheel.
sample input to
sample
10 3 4 5
Sample output Sample
outputs
5
data
size & Hint
For 30% of data, 0 < K < 7;
For 80% of data, 0 < K < 10^7;
For 100% data, 1 < n < 1,000,000,0 < m < n,1 <= x <=n,0 < K < 10^9.
Although the Zhucheng one has this sad drama of the layout or to put the topic
In short, it simply asks [M* (10^k) +x] mod n,
It's also worth noting: A*b+c mod n≠[(a*b mod n) +c] mod n
So we're directly on the code.
--Dance to understand the shadow, what seems to be in the Earth
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Basic Exercise" "Fast Power" codevs3285 Circle Game