Brush over a NOIP2013 circle game

Source: Internet
Author: User

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

Data range: 0<n<10^6,0<m<n,0<x<=n,0<k<10^9

Were you extremely surprised when you saw 0<k<10^9? What the! 10 of 100 million times!!!! Then you can only use the fast power ...

1#include <iostream>2 #definell Long Long3 using namespacestd;4 ll N,m,x,k;5ll Fast_mi (Long LongXLong LongY//Fast Power6 {7ll temp=1;8      while(y)9     {Ten         if(y&1) temp=temp*x%N; Onex=x*x%N; Ay>>=1; -     } -     returntemp%N; the } - intMain () - { -scanf"%lld%lld%lld%lld",&n,&m,&k,&x); +ll Ans=fast_mi (Ten, k)%N; -ans=ans*m%N; +ans= (ans+x)%N; Aprintf"%lld", ans); at     //System ("Pause>nul"); -     return 0; -}
C + + answer

Brush over a NOIP2013 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.