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

  1. 3 2 4
  2. 4 3 5

Sample Output

  1. 1
  2. 4

Hint

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

  1. #include<stdio.h>
  2. typedef long long ll;
  3. ll quickmod(ll a, ll b, ll m)
  4. {
  5. ll ans = 1;
  6. while (b)
  7. {
  8. if (b & 1)
  9. {
  10. ans = (ans%m*a) % m;
  11. b--;
  12. }
  13. b >>= 1;
  14. a = a%m*a%m;
  15. }
  16. return ans%m;
  17. }
  18. int main()
  19. {
  20. ll m, n, c;
  21. while (~scanf("%lld%lld%lld", &n, &m, &c))
  22. {
  23. printf("%lld\n", quickmod(n, m, c));
  24. }
  25. return 0;
  26. }
  27. /**********************************************************************
  28. Problem: 1162
  29. User: leo6033
  30. Language: C++
  31. Result: WA
  32. **********************************************************************/
改成了unsigned long long以后直接快速幂  wa!!!
然后看了别人的博客之后 用二分法实现乘法  这数据是要有多大!QAQ

  1. #include<stdio.h>
  2. typedef unsigned long long ll;
  3. ll mod_(ll a, ll b, ll m)
  4. {
  5. if (b == 0)
  6. return 0;
  7. ll r = mod_(a, b / 2, m);
  8. r = (r + r) % m;
  9. if (b % 2)
  10. r = (r + a) % m;
  11. return r;
  12. }
  13. ll mod(ll a, ll b, ll c)
  14. {
  15. if (b == 0)return 1;
  16. ll r = mod(a, b / 2, c);
  17. r = mod_(r, r, c);
  18. if (b % 2)
  19. r = mod_(r, a, c);
  20. return r;
  21. }
  22. int main()
  23. {
  24. ll m, n, c;
  25. while (~scanf("%lld%lld%lld", &n, &m, &c))
  26. {
  27. printf("%lld\n", mod(n, m, c));
  28. }
  29. return 0;
  30. }
  31.  
  32. /**********************************************************************
  33. Problem: 1162
  34. User: leo6033
  35. Language: C++
  36. Result: AC
  37. Time:28 ms
  38. Memory:1120 kb
  39. **********************************************************************/


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. 从零搭建SSM框架(一)搭建工程

    工程结构 一.cnki-parent 1.新建maven project  2.pom.xml <project xmlns="http://maven.apache.org/POM/ ...

  2. 【Swift】UIAlertController使用

    func clickButton1(){ 创建uialertcontroller var alertCtl : UIAlertController = UIAlertController(title: ...

  3. 11个实用的CSS学习工具[转载收藏]

    1. 盒子模型的幻灯片 通过3D转换效果产生的互动的幻灯片.按向左或向右箭头键切换,全屏观看会有更好的效果. 2. CSS Diner 通过一个简单的小游戏让你学习CSS selector,输入正确的 ...

  4. LintCode 204: Singleton

    LintCode 204: Singleton 题目描述 单例是最为最常见的设计模式之一.对于任何时刻,如果某个类只存在且最多存在一个具体的实例,那么我们称这种设计模式为单例.例如,对于class M ...

  5. SpringMVC控制器 跳转到jsp页面 css img js等文件不起作用 不显示

    今天在SpringMVC转发页面的时候发现跳转页面确实成功,但是JS,CSS等静态资源不起作用: 控制层代码: /** * 转发到查看培养方案详情的页面 * @return */ @RequestMa ...

  6. 更改arch的默认终端

    实在是厌倦了gnome的资源管理器nautilus和终端gnome-terminal,于是卸载之,然后更换了xfce4的终端,但是出现了一个问题,那就是在资源管理器中使用邮件打开终端的时候打不开了,解 ...

  7. shell变量$#,$@,$0,$1,$2的含义

    linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...

  8. K/V式枚举

    public enum OType { LOGIN { public String getDesc() { return "登录"; } }, ADD { public Strin ...

  9. 基于timestamp和nonce的防止重放攻击方案

    参考:http://blog.csdn.net/koastal/article/details/53456696

  10. linux 下用户组、文件权限详解

    参考资料:http://www.cnblogs.com/123-/p/4189072.html