zoukankan      html  css  js  c++  java
  • 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

    Hint

    #include<cstdio>
    #include<iostream>
    using namespace std;
    typedef unsigned long long ull;
    unsigned long long fast_mod(ull a,ull b,ull mod)
    {
        ull res=0;
        while(b)
    	{
            if(b&1) res=(res+a)%mod;
            a=(2*a)%mod;
            b>>=1;    
        }
        return res;
    }
    
    unsigned long long work(ull a,ull b,ull mod)
    {
        ull res=1;
        while(b)
    	{
            if(b&1)
                res=fast_mod(res,a,mod);
            a=fast_mod(a,a,mod);
            b>>=1;
        }
        return res;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        ull a,b,c;
        while(cin>>a>>b>>c)
    	{
            cout<<work(a,b,c)<<endl;
        }
        return 0;
    }
    /**********************************************************************
    	Problem: 1162
    	User: song_hai_lei
    	Language: C++
    	Result: AC
    	Time:60 ms
    	Memory:2180 kb
    **********************************************************************/
    



  • 相关阅读:
    QT 十六进制字符串转化为十六进制编码
    C语言中函数有输出参数
    QT 字符串相等间距字符间增加字符
    CRC校验算法
    QT 环境下开发socketCan接口程序
    QT 十六进制整数变为字符串自动补0 && 十进制补零
    C语言函数返回数组
    JNI文件中命名类与JAVA文件中匹配
    mini6410-JNI-led
    gis 出现问题解决办法
  • 原文地址:https://www.cnblogs.com/csushl/p/9386562.html
Copyright © 2011-2022 走看看