public class Example5.28 {
public static void main(String[] args) {
System.out.println("p"+"\t"+"2^p-1");
for(int p=2; p<=31; p++){
int k = pDeZhi(p);
if(isPrime(k) == true){
System.out.println(p+"\t"+k);
}
}
}
//是否素数
public static boolean isPrime(int n){
boolean str = true;
for(int i=2; i<n/2; i++){
if(n%i == 0)
str = false;
}
return str;
}
//数值2^p-1
public static int pDeZhi(int m){
return (int)(Math.pow(2,m)-1);
}
}