zoukankan      html  css  js  c++  java
  • CSU 1162【Balls in the Boxes】

    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

    • 题解:m个不同的球放进n个不同的盒子,因为每个球都有n种放法,所以答案为n的m次方。快速幂上模板解决。
    • 代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <vector>
    #include <set>
    #include <map>
    #define LL long long
    using namespace std;
    LL n,m,c;
    LL mod;
    LL quick_pow(LL a,LL b){
        LL res=1;
        a=a%mod;
        while(b){
            if(b&1){
                res=(res%mod*a)%mod;
            }
            b>>=1;
            a=(a%mod*a%mod)%mod;
        }
        return res%mod;
    }
    int main()
    {
        while(~scanf("%lld %lld %lld",&n,&m,&mod)){
            printf("%lld
    ",quick_pow(n,m));
        }
        return 0;
    }
    

  • 相关阅读:
    [日志]一个父亲给儿子的忠告
    [健康]预防手足口病中医有妙方
    [日志]教你怎么用一句话把人弄的又好气又好笑
    [健康]出汗与人健康
    [健康]四招,清除体内“垃圾”
    [健康]生病了绝对不能吃的东西
    [日志]塑造自己品牌的方法
    [健康]肾的保健按摩
    [日志]经典道歉短信
    [日志]几个笑话顿悟人生道理
  • 原文地址:https://www.cnblogs.com/kzbin/p/9205222.html
Copyright © 2011-2022 走看看