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
**********************************************************************/

Balls in the Boxes的更多相关文章

  1. CSUOJ 1162 Balls in the Boxes 快速幂

    Description Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of th ...

  2. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  3. Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟

    C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  5. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

  6. 2016 多校联赛7 Balls and Boxes(概率期望)

    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. ...

  7. HDU 5810 Balls and Boxes 数学

    Balls and Boxes 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  8. hdu-5810 Balls and Boxes(概率期望)

    题目链接: Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/O ...

  9. Educational Codeforces Round 31- D. Boxes And Balls

    D. Boxes And Balls time limit per test2 seconds memory limit per test256 megabytes 题目链接:http://codef ...

随机推荐

  1. Elasticsearch生产环境遇到的问题以及解决方案

    Elasticsearch是一个开源的分布式实时搜索与分析引擎,支持云服务.它是基于Apache Lucene搜索引擎的类库创建的,提供了全文搜索能力.多语言支持.专门的查询语言.支持地理位置服务.基 ...

  2. Kubernetes Horizontal Pod Autoscaling

    HPA介绍 Horizo​​ntal Pod Autoscaler基于观察到的CPU利用率(或借助自定义指标 支持,基于其他一些应用程序提供的指标)自动缩放复制控制器,部署或副本集中的Pod数量 .请 ...

  3. MD5 加盐加密

    一.概述 MD5(Message Digest  Algorithm 5),是一种散列算法,是不可逆的,即通过md5加密之后没办法得到原文,没有解密算法. 在一般的项目中都会有登录注册功能,最简单的, ...

  4. Java基础:8种基本数据类型,取值范围和储存字节说明。

    Java中,一共有8种基本数据类型: 4种整数型:int,short,long,byte. 2种浮点型:float,double. 1种字符类型:char. 1种表示真值的类型:boolean. [S ...

  5. hdu 2516 取石子游戏 (Fibonacci博弈)

    取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. python:类5——Python 的类的下划线命名有什么不同?

    首先是单下划线开头,这个被常用于模块中,在一个模块中以单下划线开头的变量和函数被默认当作内部函数,如果使用 from a_module import * 导入时,这部分变量和函数不会被导入.不过值得注 ...

  7. python:类4——魔法方法(定制序列、迭代)、生成器、推导式

    一.定制序列(容器类型) http://bbs.fishc.com/forum.php?mod=viewthread&tid=48793&extra=page%3D1%26filter ...

  8. windows版的mysql主从复制环境搭建

    背景 最近在学习用Spring Aop来实现数据库读写分离的功能. 在编写代码之前,首先是要部署好mysql的环境,因为要实现读写分离,所以至少需要部署两个mysql实例,一主一从,并且主从实例之间能 ...

  9. react -Route exact Redirect

     exact是Route下的一个属性,react路由会匹配到所有能匹配到的路由组件,exact能够使得路由的匹配更严格一些(exact的值为bool型).   <Route path='/' c ...

  10. 使用python脚本执行地理处理工具

    桌面ArcGIS包含800多种可在Python脚本中运行的地理处理工具. 通过Python脚本来运行地理处理工具,可以处理复杂的工作和执行批处理任务. 案例一:使用脚本执行地理处理工具(以裁剪为例) ...