does anyone know about the following error
Code:
package funfun;
import java.math.BigInteger;
/**
*
* @author ajay
*/
public class Fun{
private final static BigInteger ONE=new BigInteger("1");
private final static BigInteger ZERO=new BigInteger("0");
private final static BigInteger TWO=new BigInteger("2");
public static BigInteger sqrt(BigInteger n) {
BigInteger a = BigInteger.ONE;
BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString());
while (b.compareTo(a) >= 0) {
BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString());
if (mid.multiply(mid).compareTo(n) > 0) {
b = mid.subtract(ONE);
} else {
a = mid.add(ONE);
}
}
return a.subtract(ONE);
}//end of sqrt of n
//legendre symbol
public BigInteger legende(BigInteger n, int s) {
BigInteger mone = new BigInteger("-1");
BigInteger p = new BigInteger("" + s);
BigInteger d = p.subtract(ONE).divide(TWO);
BigInteger c = n.modPow(d, p);
if (c.compareTo(ONE) == 0) {
return ONE;
} else {
return ZERO;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int fcount=8;
int [] factorbase={2,3,11,17,19,23,43,47};
int k=0;
BigInteger n= new BigInteger("1042387");
BigInteger Sqrt=sqrt(n);
BigInteger t=Sqrt.add(ONE);
int sscount=0;
BigInteger [] s=new BigInteger[500];
BigInteger f;
BigInteger m;
while(t.compareTo(Sqrt.add(BigInteger.valueOf(41))!=0)
{
f=t.multiply(t).subtract(n).mod(n);
for(int i=0;i<fcount;i++)
{
BigInteger z= BigInteger.valueOf(factorbase[i]);
m=f.mod(z);
if(m.compareTo(ZERO)==0)
{
s[k]=f;
k++;
sscount++;
}
}
}
for(int q=0;q<sscount;q++)
{
System.out.println(""+s[q]);
}
// if(jTextField2.getText().isEmpty())
// jTextField2.setText(jTextField2.getText()+s[q]);
// else
// jTextField2.setText(jTextField2.getText()+","+s[q]);
}
}
run:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 500
at funfun.Fun.main(Fun.java:6
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)