"Basic Exercise" "Fast Power" codevs3285 Circle Game

Source: Internet
Author: User

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

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.