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. 雅虎日本如何用 Pulsar 构建日均千亿的消息平台

    雅虎日本是一家雅虎和软银合资的日本互联网公司,是日本最受欢迎的门户网站之一.雅虎日本的互联网服务在日本市场占主导地位. 下图从三个维度显示了雅虎日本的经营规模.第一个是服务数量,雅虎日本提供上百种互联 ...

  2. VS安装

    1. 只更改工作负载和单个组件 工作负载:我只勾选3个需要的 单个组件:  勾选  .NET 下Framework   别的不用改 2.点击安装,安装完成重启

  3. Mybatis 关联对象不能输出的解决办法

    Mybatis 关联对象不能输出的解决办法 1.如图所示,现在进行查询的时候并没有得到来自另一张表address项 2.我们进行如下配置: (1).在mybatis-config.xml 文件中配置, ...

  4. 编写 Dockerfile 最佳实践

    官方仓库虽然有数十万计的免费镜像,但大多数无法直接满足公司业务需求,这就需要我们自己去定制镜像了. Docker通过Dockerfile自动构建镜像,Dockerfile是一个包含用于组建镜像的文本文 ...

  5. 力扣(LeetCode)平方数之和 个人题解

    给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c. 示例1: 输入: 5 输出: True 解释: 1 * 1 + 2 * 2 = 5 示例2: 输入: 3 ...

  6. windows下安装Apache、php、mysql集成环境

    一.准备工作 本次安装的版本分别为:apache2.4  .php5.6 . mysql5.7 下载地址为:http://pan.baidu.com/s/1boQNIOn 密码:zarx 二.安装步骤 ...

  7. useReducer代替Redux

    创建state.js import React, { createContext,useContext,useReducer } from 'react'; export const countTex ...

  8. ubuntu server 1604 设置笔记本盒盖 不操作

    sudo vim /etc/systemd/logind.conf   //打开配置文件 找到 #HandleLidSwitch=suspend  改为 HandleLidSwitch=ignore  ...

  9. GitHub上优秀的开源项目(转载)

    转载出处:https://github.com/Trinea/android-open-project 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.A ...

  10. Few-shot Object Detection via Feature Reweighting (ICCV2019)

    论文:https://arxiv.org/abs/1812.01866 代码:https://github.com/bingykang/Fewshot_Detection 1.研究背景 深度卷积神经网 ...