FZU 1650 1752 a^b mod c
http://acm.fzu.edu.cn/problem.php?pid=1752
http://acm.fzu.edu.cn/problem.php?pid=1650
给跪了。
我的快速幂会越界。。
学习学习大神们的方法。。位运算好强大~
以后干脆当模版用好了- -|||
#include <cstdio>
typedef unsigned long long LL;
LL mod;
LL mul(LL a,LL b,LL c) //用快速幂的思想求a*b%c防止越界
{
LL ret=0,tmp=a%c;
while(b)
{
if(b&1)
if((ret+=tmp)>=c)
ret-=c;
if((tmp<<=1)>=c)
tmp-=c;
b>>=1;
}
return ret;
}
void pow_mod(LL a,LL n)
{
LL ret=1;
while(n) //a^n %mod
{
if(n & 1)
ret=mul(ret,a,mod);
a=mul(a,a,mod);
n>>=1;
}
printf("%llu\n",ret);
} int main()
{
LL a,b;
while(~scanf("%llu%llu%llu",&a,&b,&mod))
{
pow_mod(a,b);
}
return 0;
}
FZU 1650 1752 a^b mod c的更多相关文章
- 福州大学oj 1752 A^B mod C ===>数论的基本功。位运用。五星*****
Problem 1752 A^B mod C Accept: 579 Submit: 2598Time Limit: 1000 mSec Memory Limit : 32768 KB P ...
- [FOJ 1752] A^B mod C
Problem 1752 A^B mod C Accept: 750 Submit: 3205Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- FZU 1752 A^B mod C(快速加、快速幂)
题目链接: 传送门 A^B mod C Time Limit: 1000MS Memory Limit: 65536K 思路 快速加和快速幂同时运用,在快速加的时候由于取模耗费不少时间TLE了 ...
- FZU 1759 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- FZU 1759-Super A^B mod C
传送门:http://acm.fzu.edu.cn/problem.php?pid=1759 Accept: 1161 Submit: 3892Time Limit: 1000 mSec ...
- FZU:1759-Problem 1759 Super A^B mod C (欧拉降幂)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1759 欧拉降幂是用来干啥的?例如一个问题AB mod c,当B特别大的时候int或者longlong装不下的时 ...
- FZU Super A^B mod C(欧拉函数降幂)
Problem 1759 Super A^B mod C Accept: 878 Submit: 2870 Time Limit: 1000 mSec Memory Limit : 327 ...
- Day7 - B - Super A^B mod C FZU - 1759
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
随机推荐
- 洛谷——T1725 探险
http://codevs.cn/problem/1725/ 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 Descri ...
- golang 简单web服务
1.golang print输入 package main import "fmt" func main() { fmt.Printf("Hello World!\n&q ...
- 类似C语言格式化输出
java se5引入的format方法可以用于PrintStream或PrintWriter对象,format方法模仿自C的printf(), 如果你比较怀旧的话,也可以用printf(). pack ...
- mysql 批量删除数据
批量删除2000w数据 使用delete from table太慢 //DELIMITER DROP PROCEDURE if EXISTS deleteManyTable; create PROCE ...
- Cisco安全防护读书笔记之一Cisco系统设备协议漏洞
650) this.width=650;" onclick='window.open("http://blog.51cto.com/viewpic.php?refimg=" ...
- C# 截取中英文混合字符串分行显示宽度相同
/// <summary> /// 截取方法名显示宽度 /// </summary> /// <param name=" ...
- 字符设备驱动-------Linux异常处理体系结构
裸机中断流程 外部触发 CPU 发生中断, 强制的跳到异常向量处 跳转到具体函数 保存被中断处的现场(各种寄存器的值) 执行中断处理函数,处理具体任务 恢复被中断的现场 Linux处理异常流程 异常发 ...
- 微信小程序实现一个简单的表格
wxml <view class="table"> <view class="tr bg-w"> <view class=&quo ...
- Android 内存监测工具
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 文/幻影浪子 [博主导读]俗话说:工欲善其事必先利其器!我们先来了解下内存监测工具是怎么使用的?为内 ...
- spring+mybatis+Atomikos JTA事务配置说明
一.概览 Atomikos是一个公司名字,旗下最著名的莫过于其Atomikos的事务管理器产品.产品分两个:一个是开源的TransactionEssentials,一个是商业的ExtremeTrans ...