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

简单题,快速幂
/***************************************************/
数据更新了就wa了!!!

#include<stdio.h>
typedef long long ll;
ll quickmod(ll a, ll b, ll m)
{
ll ans = 1;
while (b)
{
if (b & 1)
{
ans = (ans%m*a) % m;
b--;
}
b >>= 1;
a = a%m*a%m;
}
return ans%m;
}
int main()
{
ll m, n, c;
while (~scanf("%lld%lld%lld", &n, &m, &c))
{
printf("%lld\n", quickmod(n, m, c));
}
return 0;
}
/**********************************************************************
Problem: 1162
User: leo6033
Language: C++
Result: WA
**********************************************************************/
改成了unsigned long long以后直接快速幂  wa!!!
然后看了别人的博客之后 用二分法实现乘法  这数据是要有多大!QAQ

#include<stdio.h>
typedef unsigned long long ll;
ll mod_(ll a, ll b, ll m)
{
if (b == 0)
return 0;
ll r = mod_(a, b / 2, m);
r = (r + r) % m;
if (b % 2)
r = (r + a) % m;
return r;
}
ll mod(ll a, ll b, ll c)
{
if (b == 0)return 1;
ll r = mod(a, b / 2, c);
r = mod_(r, r, c);
if (b % 2)
r = mod_(r, a, c);
return r;
}
int main()
{
ll m, n, c;
while (~scanf("%lld%lld%lld", &n, &m, &c))
{
printf("%lld\n", mod(n, m, c));
}
return 0;
} /**********************************************************************
Problem: 1162
User: leo6033
Language: C++
Result: AC
Time:28 ms
Memory:1120 kb
**********************************************************************/


CSUOJ 1162 Balls in the Boxes 快速幂的更多相关文章

  1. Open judge C16H:Magical Balls 快速幂+逆元

    C16H:Magical Balls 总时间限制:  1000ms 内存限制:  262144kB 描述 Wenwen has a magical ball. When put on an infin ...

  2. Balls in the Boxes

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

  3. A - Alice and the List of Presents (排列组合+快速幂取模)

    https://codeforces.com/contest/1236/problem/B Alice got many presents these days. So she decided to ...

  4. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  5. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  6. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

    题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                  ...

  7. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

  8. GDUFE-OJ 1203x的y次方的最后三位数 快速幂

    嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...

  9. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

随机推荐

  1. R5—字符串处理/正则表达式

    R通常被用来进行数值计算比较多,字符串处理相对较少,而且关于字符串的函数也不多,用得多的就是substr.strsplit.paste.regexpr这几个了.实际上R关于字符串处理的功能是非常强大的 ...

  2. Python中的and和or

    引子: 出现以上情况的原因是什么呢? print(bool('')) # False print(bool(0)) # False 所有变量的位操作都是通过强制转换成bool实现的,并且表达式的值是从 ...

  3. OpenCV LIBTIFF_4.0 link errors

    以前用Caffe用的好好的,今天重装后居然报了很多这样的错误 /usr/lib/libopencv_highgui.so.' 1> /usr/lib/libopencv_highgui.so.' ...

  4. http方式传递参数值转义或乱码的处理(base64)

    如果通过http方式传递参数url编码了,可用urlEncode和urlDecode,这种方式不同开发语言编码出来的可能不同,所以不同开发语言最好用base64编码和解码来处理: base64加密: ...

  5. 状压dp+floyed(C - Hie with the Pie POJ - 3311 )

    题目链接:https://cn.vjudge.net/contest/276236#problem/C 题目大意: 给你一个有n+1(1<=n<=10)个点的有向完全图,用矩阵的形式给出任 ...

  6. 2016.6.19——Length of Last Word

    Length of Last Word 本题收获: 1.str.size()为负 2.size_t引发的死循环 3.题目思路,有时在写代码时很不清楚边界条件的输出值是什么,若为面试,一定要问清楚. 题 ...

  7. USB设备被识别流程【转】

    转自:http://blog.csdn.net/myarrow/article/details/8286876 USB模块包括usb core,host,hub,device驱动,其中hub会启动一个 ...

  8. django Rest Framework----APIView 执行流程 APIView 源码分析

    在django—CBV源码分析中,我们是分析的from django.views import View下的执行流程,这篇博客我们介绍django Rest Framework下的APIView的源码 ...

  9. 转:vue-cli的webpack模板项目配置文件分析

    转载地址:http://blog.csdn.net/hongchh/article/details/55113751 一.文件结构 本文主要分析开发(dev)和构建(build)两个过程涉及到的文件, ...

  10. C++ : Boost : Rational 有理数类

    因为一些不为人知的原因, 我需要一些能减少我程序误差的东西.于是找到了这个类. 然后下载了Boost这个庞大的库. 安装与配置 在官网上找到下载地址, 大概有71MB, 下来来解压到任意位置就好了. ...