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,假如有 ...
随机推荐
- 【D3 API 中文手冊】
[D3 API 中文手冊] 声明:本文仅供学习所用,未经作者同意严禁转载和演绎 <D3 API 中文手冊>是D3官方API文档的中文翻译. 始于2014-3-23日,基于VisualCre ...
- 9.Maven之(九)依赖关系
转自:https://yq.aliyun.com/ziliao/312160 在maven的管理体系中,各个项目组成了一个复杂的关系网,但是每个项目都是平等的,是个没有贵贱高低,众生平等的世界,全球每 ...
- Java学习笔记八
IO流:就是input/output输入/输出流. 一.字节流操作文件的便捷类:FileWriter和FileReader import java.io.FileWriter; import java ...
- 三、Docker镜像的相关操作
原文:三.Docker镜像的相关操作 一.查看本地镜像: docker images 二.使用某个镜像来运行容器: docker run -t -i xxxx(镜像名):xx.xx(版本,不带即最新) ...
- Unity5中的粒子缩放(附测试源码)
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/49363241 作者:car ...
- 代码生成器实现的Entity,Dao,Service,Controller,JSP神器(含代码附件)
package com.flong.codegenerator; import java.sql.Connection; import java.sql.DatabaseMetaData; impor ...
- Objective-C - 类的静态常量
创建头文件(.h), 导出常量: // Constants.h FOUNDATION_EXPORT NSString *const MyFirstConstant; FOUNDATION_EXPORT ...
- Android判断App是否在前台运行
版权声明:本文为博主原创文章,未经博主允许不得转载. //当前应用是否处于前台 private boolean isForeground(Context context) { if (context ...
- event事件对象 兼容写法:var oEvent=ev||event;和取消事件冒泡
要在整个页面添加事件要使用document,例如要捕抓鼠标位置 document.onclink=function(ev) //FireFox Chrome默认都是有一个值传进来的 { var oE ...
- golang sort
package main import ( "fmt" "strings" "sort" ) type Animals []string f ...