bzoj1965 [Ahoi2005]shuffle Shuffle

Source: Internet
Author: User
Tags shuffle shuffle

In recognition of description's contribution to Samuel's expedition to the planet, Xiao Lian was invited to participate in a near-manned expedition to the Samuel Planet. Because the Samuel Planet is quite remote and scientists are going to spend quite a bit of time in the spaceship, Xiao Lian proposes to use poker to kill the boring time in the long journey. After playing a few innings, people thought it would be too easy for a high IQ person like them to play poker alone. Someone has proposed a new way to play poker. A shuffle for poker is defined like this, divide a stack of n (even) cards into the upper and lower stacks, take the first of the following stacks as the first of the new stacks, then take the first of the upper stacks as the second sheet of the new stack, and take the second of the following stacks as the third of the new stacks ... So alternating until all the cards are taken out. If you are on a stack of 6 cards 1 2 3 4 5 6, the process of making a shuffle is as follows: You can see that after a shuffle, the sequence 1 2 3 4 5 6 becomes 4 1 5 2 6 3. Of course, a shuffle of the resulting sequence will change to 2 4 6 1 3 5. The game is this, if a stack of cards of a given length of N, and the face size from 1 to a continuous increase to n (regardless of the suit), for such a stack of cards, the M shuffle. The first to say after the shuffle of cards in the sequence of cards in the face of the card size is the number of scientists victorious. Little Lenovo wins the game of victory, can you help him? Input has three integers with a space interval, representing n,m,l (where 0< n≤10 ^ 10, 0≤m≤10^ 10, and N is even). Output line outputs the face size of the specified poker card. Sample Input6 2 3
Sample Output6
  This problem is very annoying ah and is extremely disgusting to find the law on the inverse of the first carefully observe the transformation conditions, you can find from the first card ran to the second card there, the second card becomes the fourth card, and then it becomes this: 1->2->4->8->16 ... If n is not so large, careful observation will find that each is actually the result of n+1 to die the results such as n=6, that is 1->2->4->1->2->4 such as n=10, is 1->2->4->8->5- >10->9->7->3->6->1 then the problem becomes (2^m*x) ≡l (mod n+1) x then 2 in mod n+1 meaning the inverse is n/2+1 thereupon (n/2+1) ^m*x≡l (mod n+1) Move the X≡ (n/2+1) ^m*l (mod n+1) and then the quick power is done.
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < algorithm> #include <cmath> #include <queue> #include <deque> #include <set> #include <map > #include <ctime> #define LL long long#define inf 0x7ffffff#define mod (LL) (N+1LL) using namespace Std;inline ll re AD () {    LL X=0,f=1;char Ch=getchar ();    while (ch< ' 0 ' | | Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();}    return x*f;} ll N,m,l,ans;inline ll Quickpow (ll A,ll b) {ll m=a,s=1ll;while (b) {if (b&1) s= (s*m)%mod;m= (m*m)%mod;b>>=1;} return s;} int main () {n=read (); M=read (); L=read (); Ans=quickpow ((LL) n/2+1,m) ans= (ans*l)%mod;printf ("%lld\n", ans);}

 

bzoj1965 [Ahoi2005]shuffle Shuffle

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.