3285 Circling Games
2013 Noip National League Improvement Group
time limit: 1 sspace limit: 128000 KBtitle level: Diamonds Diamond SolvingView Run ResultsTitle 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.
Output 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
Sample Input
10 3 4 5
Sample output
Sample Output
5
Data range and Tips
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.
Category labels
Tags Click here to expandFast Power number theory Continental region NOIP National League increase Group 2013
be defeated by the law
AC Code:
#include <cstdio>#include<iostream>using namespacestd;Long Longn,m,k,x;Long LongQuick_pow (Long LongBLong Longa) { if(!a)return 1; if(a&1)return(Quick_pow (b,a-1)%n*b)%N; Long LongT=quick_pow (b,a/2)%N; return(t*t)%N;}intMain () {CIN>>n>>m>>k>>x; Long LongAns= (X+m%n*quick_pow (Ten, k))%N; cout<<ans<<Endl; return 0;}
3285 Circle Game