java语言程序设计第十版(Introduce to java 10th) 课后习题 chapter6-27
自己纯手工,欢迎讨论
package chapter6;
public class T28 {
public static void main(String[] args) {
System.out.println("p\t"+"2^p-1");
System.out.println("---------------");
for(int i=2;i<=31;i++){
if(isPrime((long)Math.pow(2, i)-1))
System.out.println(i+"\t"+((long)Math.pow(2, i)-1));
}
}
public static boolean isPrime(long n){
for(int i=2;i<Math.sqrt(n);i++){
if(n%i==0)
return false;
}
return true;
}
}