我正在尝试使用 AKS 算法对 16 位长的数字执行素数检查。我不断收到错误消息。有人可以编译我的代码并帮助我了解我在哪里犯了错误。(我要编译的数字示例:1425412525412545。)
这是我的 AKSPrime 课程:
import java.math.BigInteger;
public class AKSPrime
{
public static void main(String[] args)
{
AKSPrime p = new AKSPrime();
TextReader k = new TextReader();
System.out.print("Input number for primality testing: ");
int i = k.readInt();
System.out.println("Is " + i + " prime? " + p.isPrime(i));
}
public boolean isPrime(int numberToTest)
{
boolean prime = true;
boolean flag = true;
boolean suitableQFound = false;
boolean polynomialsCongruent = true;
int b, q;
int suitableQ;
double power;
for(int a = 2; a <= Math.sqrt(numberToTest); a++)
{
b = 2;
power = Math.pow(a, b);
while(!(power > numberToTest))
{
power = Math.pow(a, b);
if(power == numberToTest)
{
prime = false;
break;
}
b++;
}
}
// Algorithm Line 2
int r = 2;
// Algorithm Line 3
while( r < numberToTest && flag && !suitableQFound)
{
//Algorithm Line 4
if(GCD(numberToTest, r) != 1)
{
return false;
}
//Algorithm Line 5
if(nonAKSisPrime(r))
{
// Algorithm Line 6
q = largestPrimeFactor(r - 1);
double sqrtR = Math.sqrt(r);
double logN = Math.log(numberToTest)/Math.log(2);
// Algorithm Line 7
if( q >= 4*Math.sqrt(r)*Math.log(numberToTest)/Math.log(2) )
{
// Algorithm Line 8
suitableQ = q;
suitableQFound = true;
}
}
// Algorithm Line 9
if(!suitableQFound)
r++;
}
catspeake
繁星淼淼
相关分类