模板:
大素数判断 java
2010-06-03 22:22
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
static Scanner in;
static PrintWriter out;
public static void main(String[] args) throws Exception {
in = new Scanner(System.in);
out = new PrintWriter(System.out);
int number;
number = in.nextInt();
int result[] = new int[number];
for(int i = 0;i<number;i++)
{
BigInteger a;
a=in.nextBigInteger();
if(a.isProbablePrime(80))
{
result[i] = 1;
//out.println("Prime");
}
else
{
result[i] = 0;
// out.println("Not Prime");
}
}
for(int i = 0;i<number;i++)
{
if(result[i] == 0)
out.println("No");
else
out.println("Yes");
}
in.close();
out.close();
}
}
==================
import java.util.*;
import java.math.*;
public class Main {
static Scanner in;
static PrintWriter out;
public static void main(String[] args) throws Exception {
in = new Scanner(System.in);
out = new PrintWriter(System.out);
int number;
number = in.nextInt();
int result[] = new int[number];
for(int i = 0;i<number;i++)
{
BigInteger a;
a=in.nextBigInteger();
if(a.isProbablePrime(80))
{
result[i] = 1;
//out.println("Prime");
}
else
{
result[i] = 0;
// out.println("Not Prime");
}
}
for(int i = 0;i<number;i++)
{
if(result[i] == 0)
out.println("No");
else
out.println("Yes");
}
in.close();
out.close();
}
}
==================