Title 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.
Input/output format
Input format:
The input file name is circle.in.
Enter a total of 1 rows, containing 4 integers n, m, K, X, separated by a space between each of the two integers.
Output format:
The output file name is Circle.out.
Output a total of 1 rows, containing 1 integers, representing 10
The position number of the small partner X after the K-wheel.
Input and Output Sample input example # #:
10 3 4 5
Sample # # of output:
5
Description
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
Code
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <algorithm>5 #definell Long Long6 using namespacestd;7 8 ll N,m,k,x;9 Ten ll Pow (ll x,ll N) { Onell ans=M; A while(n) { - if(n&1) ans= (ans%n) * (xN); -x= (x%n) * (xN); then>>=1; - } - returnans; - } + - intMain () { + //freopen ("circle.in", "R", stdin); A //freopen ("Circle.out", "w", stdout); at -Cin>>n>>m>>k>>X; -cout<< (X+pow (Ten, K))%n<<Endl; - - return 0; -}
is a question of a quick power.
NOIp #3 Circle Game Label: Analog