CSUOJ 1162 Balls in the Boxes 快速幂
Description
Input
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<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
**********************************************************************/
#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 快速幂的更多相关文章
- Open judge C16H:Magical Balls 快速幂+逆元
C16H:Magical Balls 总时间限制: 1000ms 内存限制: 262144kB 描述 Wenwen has a magical ball. When put on an infin ...
- Balls in the Boxes
Description Mr. Mindless has many balls and many boxes,he wants to put all the balls into some of th ...
- A - Alice and the List of Presents (排列组合+快速幂取模)
https://codeforces.com/contest/1236/problem/B Alice got many presents these days. So she decided to ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
- Codeforces632E Thief in a Shop(NTT + 快速幂)
题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...
- GDUFE-OJ 1203x的y次方的最后三位数 快速幂
嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
随机推荐
- ASP.NET项目与IE10、IE11不兼容的解决办法
1.解决办法 机器级别修复, 服务器所有ASP.NET程序受益 需要去微软下载对应asp.NET版本的修补程序 .NET 4 -http://support.microsoft.com/kb/2600 ...
- 如何给自己的PHP项目制作安装程序
最近很是激动啊,现在的自己还是和当初刚刚学习程序的时候一样,虽然现在回头一看自己写过的程序,都非常的小孩子和漏洞百出,也没有太多的考虑效率和安全,但是还是每次写出了新的程序或系统,都是抱着一种马上拿着 ...
- c++模板函数作为参数的疑惑
为什么22行只能传一个模板函数作为参数,而非模板却编译失败,求解释.
- 基本控件文档-UIButton属性
CHENYILONG Blog 基本控件文档-UIButton属性 Fullscreen UIButton属性技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博ht ...
- 20165230 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
20165230 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:田坤烨 学号:20165230 成绩: 指 ...
- 使用Picker的时候,让input输入框使用焦点,手机键盘不弹出
$("#address").click(function(){ document.activeElement.blur(); })
- 【codeforces】【比赛题解】#864 CF Round #436 (Div.2)
做出了4题,还不错,可惜还是掉rating……能保持在蓝名已经不错了. 题目跳转链接. [A]公平的游戏 题意: Petya和Vasya在玩游戏.他们有n张卡片(n是偶数).每张卡片上有一个整数. 游 ...
- Linux时间子系统之七:定时器的应用--msleep(),hrtimer_nanosleep()【转】
转自:http://blog.csdn.net/droidphone/article/details/8104433 我们已经在前面几章介绍了低分辨率定时器和高精度定时器的实现原理,内核为了方便其它子 ...
- 动态RNN和静态RNN区别
调用static_rnn实际上是生成了rnn按时间序列展开之后的图.打开tensorboard你会看到sequence_length个rnn_cell stack在一起,只不过这些cell是share ...
- 经典面试题:js继承方式上
js不是传统的面向对象语言,那么他是怎么实现继承的呢?由于js是基于原型链实现的面向对象,所以js主要通过原型链查找来实现继承,主要有两大类实现方式,分为基于构造函数的继承,以及非构造函数的继承. 由 ...