Clarification C: Balls in the Boxes CSU-1162

Description

Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of the boxes.Now, he wants to know how many different solutions he can have.
you know,he could put all the balls in one box,and there could be no balls in some of the boxes.Now,he tells you the number of balls and the numbers of boxes, can you to tell him the number of different solutions? Because the number is so large, you can just tell him the solutions mod by a given number C.
Both of boxes and balls are all different.


Input

There are multiple testcases. In each test case, there is one line cantains three integers:the number of boxes ,the number of balls,and the given number C separated by a single space.All the numbers in the input are bigger than 0 and less than 2^63.


Output

 For each testcase,output an integer,denotes the number you will tell Mr. Mindless

Sample Input

3 2 4
4 3 5

Sample Output

1
4


讀懂題意,這題就是一道快速冪的問題。直接上模板,水題。

#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <set>
using namespace std;
#define ll long long
const int maxn=305;

ll n,m,C;

ll quickmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans%m*a)%m;
            b--;
        }
        b/=2;
        a=a%m*a%m;
    }
    return ans%m;
}

int main()
{
    while(cin>>n>>m>>C)
    {
        cout<<quickmod(n,m,C)<<endl;
    }
    return 0;
}

/**********************************************************************
	Problem: 1162
	User: jk1601zr
	Language: C++
	Result: AC
	Time:36 ms
	Memory:2020 kb
**********************************************************************/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章