UVa 374 - Big Mod
题目大意:计算R = BP mod M,根据模运算的性质计算。
正常计算会超时,可以用分治的思想降低时间复杂度。不过如果遇到00,结果...话说00的结果是1吗?忘了都...
#include <cstdio> int powMod(int base, int exp, int mod)
{
if (exp == ) return ;
int res = powMod(base, exp>>, mod);
res = (res * res) % mod;
if (exp & 0x1 == ) res = (res * base) % mod;
return res;
} int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int b, p, m;
while (scanf("%d%d%d", &b, &p, &m) != EOF)
{
int res = powMod(b%m, p, m);
printf("%d\n", res);
}
return ;
}
UVa 374 - Big Mod的更多相关文章
- UVA 10692 Huge Mod
Problem X Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator f ...
- UVA - 374
https://vjudge.net/problem/19685/origin 费马小定理优化快速幂 因为加了费马小定理优化,小心2 2 2这种情况,会出现0 0 2,也就是0的0次方,实际答案为0 ...
- uva 11916 解模方程a^x=b (mod n)
Emoogle Grid You have to color an M x N ( 1M, N108) two dimensional grid. You will be provided K ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
- uva 11174 Stand in a Line
// uva 11174 Stand in a Line // // 题目大意: // // 村子有n个村民,有多少种方法,使村民排成一条线 // 使得没有人站在他父亲的前面. // // 解题思路: ...
- uva 11806 Cheerleaders
// uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...
- .Uva&LA部分题目代码
1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...
- UVA 12898 - And Or 数学
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
随机推荐
- jquery_api事件(二)
1.hover 一个模仿悬停事件的方法.它为频繁使用的任务提供了一种“保持在其中”的状态. 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数.当鼠标移出这个元素时,会触发指定的第二个函数.而且 ...
- Linux学习 -- Shell编程 -- 正则表达式
正则表达式与通配符 正则 -- 匹配字符串 -- 包含匹配 grep.awk.sed等 通配符 -- 匹配文件名 -- 完全匹配 ls.find.cp等 基础正则表达式
- 高性能IO模型浅析(转)
转自:http://www.cnblogs.com/fanzhidongyzby/p/4098546.html 是我目前看到的解释IO模型最清晰的文章,当然啦,如果想要详细的进一步了解还是继续啃蓝宝书 ...
- messages exchanged between the client's and server's computers will never be lost, damaged, or received out of order. [1]
w几乎所有的HTTP通信都由TCP/IP承载. HTTP The Definitive Guide Just about all of the world's HTTP communication i ...
- 为什么有时候必须添加sys.setdefaultencoding('utf-8')
今天在尝试Python的CGI模块时遇到中文字符不能正确显示的问题,很郁闷.在网上仔细找了找,终于解决了这个问题,现在将解决方法陈述如下,以防下次失误. 页面源代码如下 #-*- coding: ut ...
- 彻底搞明白find命令的-mtime参数的含义【转载】
转自: 彻底搞明白find命令的-mtime参数的含义-goolen-ITPUB博客http://blog.itpub.net/23249684/viewspace-1156932/ 以前一直没有弄明 ...
- mysql show processlist详解
SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此信息.如果您有SUPER权限,您可以看到所有线程.否则,您只能看到您自己的线程( ...
- byte[]和InputStream的相互转换
1:byte[]转换为InputStream InputStream sbs = new ByteArrayInputStream(byte[] buf); 2:InputStream转换为Input ...
- C++多线程一
CreateThread()创建一个新的线程. ExitThread()正常的结束一个线程的执行. CloseHandle()关闭一个线程的句柄. CreateThread()函数原型如下: HAND ...
- ural1752 Tree 2
Tree 2 Time limit: 1.0 secondMemory limit: 64 MB Consider a tree consisting of n vertices. A distanc ...