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

  1. #include<cstdio>
  2. #include<iostream>
  3. using namespace std;
  4. typedef unsigned long long ull;
  5. unsigned long long fast_mod(ull a,ull b,ull mod)
  6. {
  7. ull res=0;
  8. while(b)
  9. {
  10. if(b&1) res=(res+a)%mod;
  11. a=(2*a)%mod;
  12. b>>=1;
  13. }
  14. return res;
  15. }
  16. unsigned long long work(ull a,ull b,ull mod)
  17. {
  18. ull res=1;
  19. while(b)
  20. {
  21. if(b&1)
  22. res=fast_mod(res,a,mod);
  23. a=fast_mod(a,a,mod);
  24. b>>=1;
  25. }
  26. return res;
  27. }
  28. int main()
  29. {
  30. ios::sync_with_stdio(false);
  31. ull a,b,c;
  32. while(cin>>a>>b>>c)
  33. {
  34. cout<<work(a,b,c)<<endl;
  35. }
  36. return 0;
  37. }
  38. /**********************************************************************
  39. Problem: 1162
  40. User: song_hai_lei
  41. Language: C++
  42. Result: AC
  43. Time:60 ms
  44. Memory:2180 kb
  45. **********************************************************************/

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. VsCode Python配置安装教程

    1.软件下载地址 Python官网: https://www.python.org/downloads/windows/ Python下载地址: https://www.python.org/ftp/ ...

  2. PHP 格式化公钥私钥(pem文件)

    <?php header("Content-Type: text/html; charset=utf-8"); $filename = dirname(__FILE__).& ...

  3. 判断DataGridView是否选中某行

    if (this.Drawing_GridView.SelectedColumns.Count == 0)//判断是否选中某行 { }

  4. 阿里云ECS服务器部署HADOOP集群(三):ZooKeeper 完全分布式集群搭建

    本篇将在阿里云ECS服务器部署HADOOP集群(一):Hadoop完全分布式集群环境搭建的基础上搭建,多添加了一个 datanode 节点 . 1 节点环境介绍: 1.1 环境介绍: 服务器:三台阿里 ...

  5. selenium滑块验证

    使用selenium模拟登录解决滑块验证问题   本次主要是使用selenium模拟登录网页端的TX新闻,本来最开始是模拟请求的,但是某一天突然发现,部分账号需要经过滑块验证才能正常登录,如果还是模拟 ...

  6. selenium介绍和环境搭建

    一.简单介绍 1.selenium:Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样.支持的浏览器包括IE.Mozilla Fire ...

  7. PostGIS 报错为org.postgresql.util.PSQLException:错误: Operation on mixed SRID geometries

    说明: 在用Openlayers与Geoserver进行开发,做在线编辑功能时,出现一个问题:每当我新增了一根要素后,再次用wfs的方式进行点击查询时,会报错mixed SRID. 通过研究发现在数据 ...

  8. 在WebView中加载HTML页面时显示进度对话框的方法

    webView.setWebViewClient(new WebViewClient(){            ProgressDialog prDialog;            @Overri ...

  9. PowerMock学习(六)之Mock Final的使用

    Mock Final mockfinal相对来说就比较简单了,使用powermock来测试使用final修饰的method或class,比较简单,接口调用部分,还是service调用dao. 对于接口 ...

  10. sql server 增删改(查太多了)

    表: 学生(*学号,姓名,性别,年龄,专业) create table student( sno ) primary key, sname ) not null, ssex ), sage small ...