java大数求模的运算
来源:互联网 发布:廖雪峰python教程微盘 编辑:程序博客网 时间:2024/05/21 07:59
Modular Exponentiation
在离散数学里有大数求模的运算,例如求3^644 mod 645的结果,3^644 mod 645 =36是正确的结果
package ThisTestForProblems;import javax.swing.JOptionPane;public class ModularExponentiation {public static void main(String[] args) { /*The algorithm is to get the result b^n%m for example 3^644 % 645 =36 */ int b=Integer.parseInt(JOptionPane.showInputDialog("The algorithm to get the result of b^n % m. Please input the b ")); int n=Integer.parseInt(JOptionPane.showInputDialog("The algorithm to get the result of b^n % m. Please input the n")); char[] array=Integer.toBinaryString(n).toCharArray();/*array is the binary string of the numberN*/ int m=Integer.parseInt(JOptionPane.showInputDialog("The algorithm to get the result of b^n % m. Please input the m ")); int k=array.length; int x=1; int power=b%m; for(int i=0;i<k;i++){ if(array[k-1-i]=='1') { x=(x*power)%m; } power=(power*power)%m; } System.out.println(x);/*x is the result of b^n%m*/}}
数学原理
0 0
- java大数求模的运算
- 大数求幂运算
- 【java】求大数的阶乘
- java求大数的阶乘
- 求大数高次幂的模
- 一种求大数运算的方法,如5000!
- 大数的运算函数(Java)
- 大数的减法运算Java代码实现
- 杭电1212 Big Number (大数求模运算)
- Java中的大数运算
- JAVA大数运算
- java 大数运算
- java 大数运算[转]
- poj2305 JAVA大数运算
- java 大数运算 BinInteger
- JAVA 大数运算
- Java大数运算
- Java实现大数运算
- Qtcreator编写ros程序:无法启动进程"catkin_make" -DCMAKE_BUILD_TYPE=Debug
- 斜率优化dp学习笔记
- Create your gradle plugin
- 你首先是一个人,然后你才是程序员。
- 机器学习案例实战-信用卡欺诈检测
- java大数求模的运算
- 查找两个字符串中的最大公共子串
- poj 2965 The Pilots Brothers' refrigerator(翻转)
- C++——命名规范
- SQLLite数据库创建和使用
- shell脚本mac平台执行sed命令报错
- 最大公约数 poj
- 计算机图形学——OpenGL学习系列之绘制3D下的小桌子
- 多租户过程记录三