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
题目大意:n个不同的盒子,m个球,将m个球放进这n个盒子里面,问有多少种不同的放法。每个球有n种方法,所以总的就有n^m%C种
代码如下:
#include<iostream>
using namespace std;
#define ll long long
ll quick(ll a,ll b,ll m){
ll ans=1;
while(b){
if(b&1){
ans=ans*a%m;
}
a=a%m;
a=a*a%m;
b>>=1;
}
return ans%m;
}
int main(){
ll box,ball,mod;
while(cin>>box>>ball>>mod){
cout<<quick(box,ball,mod)<<endl;
}
return 0;
}
球盒问题求解
本文探讨了一个经典的组合数学问题——不同数量的球放入不同数量的盒子里的方法总数,并提供了一段高效的C++代码实现。该问题通过快速幂运算求解模意义下的答案。
831

被折叠的 条评论
为什么被折叠?



