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> ...
随机推荐
- angularJS 控制输入的百分数在0%-100%之间
想了老半天了,记录一下 app.directive("percentageCheck", function () { return { restrict: 'A', require ...
- Netty接收HTTP文件上传及文件下载
文件上传 这个处理器的原理是接收HttpObject对象,按照HttpRequest,HttpContent来做处理,文件内容是在HttpContent消息带来的. 然后在HttpContent中一个 ...
- jQuery插件开发中$.extend和$.fn.extend辨析
jQuery插件开发分为两种: 1 类级别 类级别你可以理解为拓展jquery类,最明显的例子是$.ajax(...),相当于静态方法. 开发扩展其方法时使用$.extend方法,即jQuery. ...
- 【转】C# Graphics类详解
Brush 类 .NET Framework 4 定义用于填充图形形状(如矩形.椭圆.饼形.多边形和封闭路径)的内部的对象. 属于命名空间: System.Drawing 这是一个抽象基类,不能进行 ...
- Linux基础-Shell脚本
任务一目标:自动部署.初始配置.并启动nginx反向代理服务 把任务拆分来看-自动部署部分,就是先下载安装Nginx 首先建立一个很NB霸气的目录还有一个同样NB霸气的.sh文件 /NBshell/M ...
- 线段树(dfs序建树加区间更新和单点查询)
题目链接:https://cn.vjudge.net/contest/66989#problem/J 记录一下这道折磨了我一天的题,.... 具体思路: 具体关系可通过dfs序建树,但是注意,在更新以 ...
- Serv-U 的升级及数据备份和迁移【转】
Serv-U 配置备份 在serv-u7.x及以上版本安装目录下,有一个文件Serv-U.Archive是serv-u的配置文件,有一个users文件夹是Serv-U的域和用户的信息,那么我们只需 ...
- 事件,使用.net自带委托EventHandler
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ARC073E Ball Coloring
Problem AtCoder Solution 把点映射至二维平面,问题就变成了给定 \(n\) 个点,可以把点对 \(y=x\) 对称,求覆盖所有点的最小矩形面积. 可以先把所有点放到 \(y=x ...
- 解决修改表结构,添加外键时出现“约束冲突”的错误
由于表结构更改,使用新建表,现有部分表需要更改外键,将引用更改到新建表的相应字段.在更改过程中,部分表出现如下错误提示: ALTER TABLE 语句与 COLUMN FOREIGN KEY 约束 ' ...