题目大意:计算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的更多相关文章

  1. UVA 10692 Huge Mod

    Problem X Huge Mod Input: standard input Output: standard output Time Limit: 1 second The operator f ...

  2. UVA - 374

    https://vjudge.net/problem/19685/origin 费马小定理优化快速幂 因为加了费马小定理优化,小心2 2 2这种情况,会出现0 0 2,也就是0的0次方,实际答案为0 ...

  3. 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  ...

  4. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

  5. 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 ...

  6. uva 11174 Stand in a Line

    // uva 11174 Stand in a Line // // 题目大意: // // 村子有n个村民,有多少种方法,使村民排成一条线 // 使得没有人站在他父亲的前面. // // 解题思路: ...

  7. uva 11806 Cheerleaders

    // uva 11806 Cheerleaders // // 题目大意: // // 给你n * m的矩形格子,要求放k个相同的石子,使得矩形的第一行 // 第一列,最后一行,最后一列都必须有石子. ...

  8. .Uva&LA部分题目代码

    1.LA 5694 Adding New Machine 关键词:数据结构,线段树,扫描线(FIFO) #include <algorithm> #include <cstdio&g ...

  9. UVA 12898 - And Or 数学

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

随机推荐

  1. haxe 配置

    安装所有类库: 命令提示符 haxelib install 类库名 如:haxelib install openfl 配置安卓: 命令提示符 haxelib run openfl setup andr ...

  2. Linux学习 -- Shell编程 -- 字符截取命令

    cut字段提取命令 cut [选项] 文件名 -f 列号: -d 分隔符: 局限性:空格为分隔符时不适用 printf命令 printf '输出类型输出格式' 输出内容 %s, %i, %f \a, ...

  3. 批量文件重命名工具-极力推荐 advanced renamer

    http://www.advancedrenamer.com/  功能太强大了,自己慢慢探索吧.

  4. CF 389 E 贪心(第一次遇到这么水的E)

    http://codeforces.com/contest/389/problem/E 这道题目刚开始想的特别麻烦...但是没想到竟然是贪心 我们只需要知道偶数的时候可以对称取的,然后奇数的时候没次取 ...

  5. javascript 按位或(|),无符号右移(>>>)运算,组合技巧来实现————密码强度提示,四种情况??

    直接上代码,原来的代码中,switch中的第一个case,判断之后,少加了个break 跳出判断语句,害得我查了半天,“怎么样式老是不对,不科学啊,呵呵,原来是没跳出case的判断了,还会执行后面的判 ...

  6. (转)多个MapReduce作业相互依赖时,使用JobControl进行管理

    原文地址:http://mntms.iteye.com/blog/2086990 要处理复杂关系的数据,一个工程里面绝对不止一个MapReduce作业,当有多个MapReduce作业时,       ...

  7. 注册表检测office版本

    #region 查询注册表,判断本机是否安装Office2003,2007和WPS public int ExistsRegedit() { int ifused = 0; RegistryKey r ...

  8. js 编码问题

    //字符转换为UTF-8编码 function encutf8(s1) { var stringArray = new Array(); for(var j=0; j<s1.length;j++ ...

  9. thin-provisioning-tools

    公司我还用着squeeze,没这个包,下载编译:https://github.com/jthornber/thin-provisioning-tools.git

  10. do from a specific ip

    ping -S 192.168.240.1 sohu.com telnet -b 192.168.240.1 sohu.com 80