求一个循环群的生成元,用java代码实现

watchdog2015 2017-05-10 09:55:27
题目:编写一个函数求循环群的一个生成元,使用java代码实现

函数输入:一个大素数p,类型为BigInteger

函数返回值:输出素域p的一个生成元g,类型为BigInteger

...全文
622 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
AttackMonster 2020-11-12
  • 打赏
  • 举报
回复
引用 1 楼 qq_38351849 的回复:
public static BigInteger getG(BigInteger p, BigInteger p_MinusOne) { BigInteger g = null; outterLoop: for (int i = 2; i < 50; i++) { for (int x1 = 1; x1 <= Integer.valueOf(p_MinusOne.toString()); x1++) { String str1 = String.valueOf(i); String str2 = String.valueOf(x1); BigInteger tmp1 = new BigInteger(str1); BigInteger tmp2 = new BigInteger(str2); if (tmp1.modPow(tmp2, p).compareTo(ONE) == 0 && tmp2.compareTo(p_MinusOne) == -1) { break; } else if (tmp1.modPow(tmp2, p).compareTo(ONE) == 0 && tmp2.compareTo(p_MinusOne) == 0) { g = tmp1; break outterLoop; } } } return g; }
p_minusOne 是什么意思
qq_38351849 2018-12-29
  • 打赏
  • 举报
回复
public static BigInteger getG(BigInteger p, BigInteger p_MinusOne) {
BigInteger g = null;

outterLoop: for (int i = 2; i < 50; i++) {
for (int x1 = 1; x1 <= Integer.valueOf(p_MinusOne.toString()); x1++) {
String str1 = String.valueOf(i);
String str2 = String.valueOf(x1);
BigInteger tmp1 = new BigInteger(str1);
BigInteger tmp2 = new BigInteger(str2);
if (tmp1.modPow(tmp2, p).compareTo(ONE) == 0 && tmp2.compareTo(p_MinusOne) == -1) {
break;
} else if (tmp1.modPow(tmp2, p).compareTo(ONE) == 0 && tmp2.compareTo(p_MinusOne) == 0) {
g = tmp1;
break outterLoop;
}
}
}

return g;
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧