普及练习场 分治算法 取余运算与快速幂
2018-01-09 17:27
295 查看
题目链接
题意理解
这条题目就是用来验板子的代码
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static class FastScanner { private BufferedReader br; private StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String nextToken() { while(st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public long nextLong() { return Long.valueOf(nextToken()); } } public static void main(String[] args) { FastScanner fs = new FastScanner(); long b = fs.nextLong(); long p = fs.nextLong(); long k = fs.nextLong(); System.out.println(b + "^" + p + " mod " + k + "=" + powMod(b, p, k)); } static long powMod(long b, long p, long k) { if(p == 0) { return 1; } long res = powMod(b, p / 2, k); res = res * res % k; if(p % 2 == 1) { res = res * b % k; } return res; } }
相关文章推荐
- 普及练习场 分治算法 幂次方
- 普及练习场 分治算法 逆序对
- 普及练习场 普及常见模板 【模板】线性筛素数
- 普及练习场 普及常见模板 【模板】单源最短路径
- 矩阵快速运算_总结
- 【分治】快速幂运算-递归与非递归方法
- 普及练习场 交叉模拟 字符串的展开
- 关于傅里叶变换的理解、快速傅里叶算法的推导以及蝶形运算的c语言实现
- 普及练习场 贪心 纪念品分组
- 结构体类型快速驱魔运算及运算符的重载
- LightOJ - 1282 B - Leading and Trailing——快速幂运算
- 普及练习场 广度优先搜索 机器人搬重物
- 矩阵运算,矩阵快速幂,模板
- 普及练习场 动态规划的背包问题 开心的金明
- Keil C51下快速小数运算算法
- JavaScript快速入门(五)——表达式运算
- 快速求幂运算笔记
- 普及练习场 排序Ex 魔法照片
- freemarker快速上手+空值+三元运算的多种处理方法
- 分治算法——快速排序、归并排序算法(Java实现)