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,假如有 ...
随机推荐
- 洛谷 P3505 [POI2010]TEL-Teleportation
P3505 [POI2010]TEL-Teleportation 题目描述 King Byteasar is the ruler of the whole solar system that cont ...
- 【Mysql】将Excel表导入至Mysql的当中一张表
如果表格有A(整型字段).B(整型字段).C(字符串数据)三列数据,希望导入到Mysql中数据库中表格table.table中须要插入的字段各自是col1,col2,col3 1.在随意一列,如果在D ...
- mac自己定义tree命令
编辑文件: vim ~/.bash_profile 在文件末尾追加: alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____| ...
- *android抓包工具——fiddler抓包分析api接口
本文地址:http://blog.csdn.net/u011733020 首先,写这个仅仅是为了学习.不是要做什么违法的事情,假设有问题,有关部门 请联系我,立刻删除. 不要查我水表. 正题:这里介绍 ...
- js09--函数 call apply
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- Vue 的 createElement 函数的参数问题的小笔记
官方文档的说明. 第二个参数的值是要生成的标签的属性数据.点击查看详情. 第三个参数则是组件标签内的数据,数据里面的内容会渲染在第一个参数的标签内.通常会在此指定各插槽 slot 对应的位置,也可以在 ...
- 免费的EmBitz可替代Keil MDK开发STM32、NXP项目
一.背景 由于使用之前开发STM32是基于Keil MDK编译环境开发的,由于该软件是收费的,想用个免费开源的软件来替代Keil,EmBitz编译器是免费的,可以完全替代开发.下载程序支持J-Link ...
- System and method for critical address space protection in a hypervisor environment
A system and method in one embodiment includes modules for detecting an access attempt to a critical ...
- PDF.Js的使用—javascript中前端显示pdf文件
PDF.Js的使用—javascript中前端显示pdf文件 写于2018/12/6 起因是一个图片展示页面需要展示pdf格式的文件,所以查了半天决定使用pdf.js,我也不求有多了解它,能实现我想要 ...
- CODEVS——T 1993 草地排水 USACO
http://codevs.cn/problem/1993/ 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题解 查看运行结果 题目描述 De ...