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,假如有 ...
随机推荐
- [置顶]
Docker学习总结(2)——Docker实战之入门以及Dockerfile(二)
csphere/php-fpm:5.4 # cd docker-training/php-fpm/ # ls Dockerfile nginx_nginx.conf supervisor_nginx. ...
- C# wpf程序获取当前程序版本
C# wpf程序获取当前程序版本 /// <summary> /// 获取当前系统的版本 /// </summary> /// ...
- layui中select的注意
假如不在select 标签里面加上过滤lay-filter 那么你就算怎么绑定事件都是没有任何效果 页面上代码 js文件:
- Js 栈和堆的实现
一.队列和堆栈的简单介绍 1.1.队列的基本概念 队列:是一种支持先进先出(FIFO)的集合,即先被插入的数据,先被取出! 1.2.堆栈的基本概念 堆栈:是一种支持后进先出(LIFO)的集合,即后被插 ...
- http 500 Internal Server Error的错误 ajax请求SpringMVC后台中返回500 Internal Server Error
使用httprequester接口测试能返回数据,但是用ajax返回json格式的时候返回报500Internal Server Error. The server encountered an in ...
- x264代码剖析(三):主函数main()、解析函数parse()与编码函数encode()
x264代码剖析(三):主函数main().解析函数parse()与编码函数encode() x264的入口函数为main().main()函数首先调用parse()解析输入的參数,然后调用encod ...
- 含有过滤功能的android流式布局
FilterFlowLayout 含有过滤功能的流式布局, 參考FlowLayout 能够去除宽度不在范围(比例或真实值)内的子view 能够设置最大行数 能够加入组件间水平间距 能够加入行间距 系统 ...
- 关于hive里安装mysql出现错误,如何删除指定的主机或用户?(解决Access denied)
前期博客 你可以按照我写的这篇博客去,按照hive的mysql. 1 复习ha相关 + weekend110的hive的元数据库mysql方式安装配置(完全正确配法)(CentOS版本)(包含卸载系统 ...
- (错误记录)git push 报错 403
在push的时候遇到错误: RPC failed; HTTP curl The requested URL returned error: Forbidden 如果是自己创建的项目的话,可以在网上找到 ...
- 深入并发AQS二
AQS须要解决下面几个问题: 1.锁状态,怎样保证并发情况下可以安全的更新? 2.当前线程不能获取锁时,放在哪里? AQS是放在一个队列其中 3.怎样提高效率? AQS的主要职责是当获取不到锁时.将线 ...