NOIP201305 Circles Game

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.