Fzu 1876 Jinyuetuan (permutation combination)

Source: Internet
Author: User

Description

Let ' s has a look at the picture below

Now, does know what it's? Yeah, O (∩_∩) o~, It is the game called Jinyuetuan. Chjing plays it very often years ago. I promise you would like it too. Now I want to introduce it to you. Maybe you have already known it clearly. Just be patient.

Jinyuetuan is a famous online game which have been in vogue for a long time. Since It is so exciting a game, a large number of players put themselves in it. Only seven keys on the keyboard is used in games, and each key is assigned to one of the seven sound tracks. During the game, a series of notes fall in each sound track irregularly. When notes fall under one sound track, player should press the assigned key at once. If So, then got a "Cool", or get "Miss" otherwise. You should press the key when the note was almost disappeared at the bottom of the window. If you press the key too early, you'll miss the note. There'll be a song or some kind of music played if you are playing the game. So you'll feel you is a pianist. As you pass a low level. The notes would be is more and the speed the notes fall would be very high. And the game would be more exciting. There is a lot of cows who play this game very well. If you had a chance to watch them playing, you would say ' Orz 'From your heart. But as a programmer, we would admire people the WHO write this game more. Here comes the problem.

If you is assigned write a game similar to this game. If there is n different sound tracks and M different notes. How many different ways can-arrange the notes to fall.

Input

There is multiple test cases, each case contains a line of three numbers n, M, p. (0 < N, m < 1000000, 0 < P &lt ; 10^10).

Output

Output the result mod p.

Sample Input

2 2 1000

Sample Output

6

Hint


We have care on the figure when the notes is piled up.  So, ignore the sequence of the notes falling in different sound tracks. Think of n orbits as n-1 partitions, and then (N-1+M)! /(N-1)! ... Break when the result equals 0; It's a hole in here.
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>#include<algorithm>#defineRoot 1,n,1#defineLson l,mid,rt<<1#defineRson mid+1,r,rt<<1|1#defineLR rt<<1#defineRR rt<<1|1using namespaceStd;typedefLong LongLL;Const intINF = 1e9+7;Const DoublePI = ACOs (-1.0);Const DoubleEPS = 1e-6 ;Const intN =1010; LL N, M, p;intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); #endif //LOCALIos::sync_with_stdio (false);  while(Cin >> n >> M >>p) {LL res=1 ;  for(inti = n + M-1; I >= N; --i) {res*= i; Res%=p; if(!res) Break ; } cout<< Res <<Endl; }}
View Code

Fzu 1876 Jinyuetuan (permutation combination)

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.