題目:撰寫一個函式求回圈群的一個生成元,使用java代碼實作
函式輸入:一個大素數p,型別為BigInteger
函式回傳值:輸出素域p的一個生成元g,型別為BigInteger
uj5u.com熱心網友回復:
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;
}
uj5u.com熱心網友回復:
p_minusOne 是什么意思
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/212874.html
標籤:Java SE
上一篇:求大佬罩著??
下一篇:(已安裝成功,內含云盤torch1.6安裝包)Jetson Nano下載opencv4.1.1,torch1.6,torchvision0.7;
