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> ...
随机推荐
- Clockwise/Spiral Rule
[Clockwise/Spiral Rule] There is a technique known as the ``Clockwise/Spiral Rule''. (顺时针螺旋法则). Ther ...
- [转载]AMD 的 CommonJS wrapping
https://www.imququ.com/post/amd-simplified-commonjs-wrapping.html 它是什么? 为了复用已有的 CommonJS 模块,AMD 规定了 ...
- 使用反射代替不断添加的if-else来实现代码的可扩展性
在调用一个自定义的GeneralHandler类里面的一个方法,该方法是针对数据库的一张表的所有操作(CRUD),根据传入的DealType来判断做那种操作 代码: using System;usin ...
- Linux基础-awk使用
打印uid在30~40范围内的用户名:awk -F: '$3>=30&&$3<040{print $1}' passwd 打印第5-10行的行号和用户名:awk -F: ' ...
- C# XML序列化和反序列化
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- Vue起步
Vue起步 Vue.js是什么 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式javascript框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用. ...
- Python模块:Random(未完待续)
本文基于Python 3.6.5的官文random编写. random模块简介 random为各种数学分布算法(distributions)实现了伪随机数生成器. 对于整数,是从一个范围中均匀选择(u ...
- 华夏部分互联网科技公司创始及IPO信息
时间:2018-04-19 前面整理了一些美国科技公司的信息,这篇文章整理的是我华夏的一些科技公司的信息. 华为.百度.阿里.腾讯.美团.携程.京东.小米.奇虎360……之后,其它一些公司,要么体量 ...
- MySQL触发器Trigger实例篇
定义: 何为MySQL触发器? 在MySQL Server里面也就是对某一个表的一定的操作,触发某种条件(Insert,Update,Delete 等),从而自动执行的一段程序.从这种意义上讲触发器是 ...
- keras LSTM中间的dropout
TM有三个 model.add(LSTM(100, dropout=0.2, recurrent_dropout=0.2)) 第一个dropout是x和hidden之间的dropout,第二个是hid ...