public class Prime {
/**
* 列出1到1000以内的的,对59求余后为1的质数。
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Prime().new thread().start();
}
class thread extends Thread
{
public void run() {
// TODO Auto-generated method stub
int a=0;
for(int i=0;i<1000;i+=59)//对59求余为1,该数肯定是59的倍数加上1后的数,
{
if(isZhiShu(i+1))//判断是否为质数。
{
a=1;
System.out.println(i+1) ;
}
}
if(a==0)
{
System.out.println("1-1000这个范围里没有这样的数") ;
}
}
}
public static boolean isZhiShu(int x)//判断是否为质数
{
for(int i=2;i
if(x%i==0)
{
return false;
}
}
return true;
}
}
public class PrimeNumber {
/**
* @param args
*/
public static void main(String[] args) {
Thread curr;
curr = Thread.currentThread();
System.out.println("列出1到1000以内的的,对59求余后为1的质数:");
for (int i = 2; i <= 1000; i++) {
for (int j = 2; j <= i - 1; j++) {
if (i % j != 0 && i % 59 == 1)
System.out.println(" " + i);
break;
}
}
try {
Thread.sleep(1000);
} catch (Exception e) {
System.out.println("异常为" + e.getMessage());
}
}
}
还有些问题,但可以做个参考!
要求还真多呢!