Accept: 238Submit: 1098
Time Limit: 2000 mSecMemory Limit : 32768 KB
Problem Description
Your task is simple. Give you a number N, you should judge whether N is a prime number or not.
Input
There are multiple test cases. For each test case, there is an integer N(2<=N<=10^18).
Output
For each test case, you should output whether N is a prime number or not. If N is a prime number , you should output "It is a prime number."; otherwise you should output "It is not a prime number.";
Sample Input
2
4
Sample Output
It is a prime number.
It is not a prime number.
--------------------------------------------------------------------------------------
我发现java越来越暴力了
import java.math.BigInteger; import java.util.Scanner; public class Main { static BigInteger b; public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNext()) { b=in.nextBigInteger(); if(b.isProbablePrime(1)) System.out.println("It is a prime number."); else System.out.println("It is not a prime number."); } } }
判断巨数质数
本文介绍了一种使用Java实现的大数质数判断方法。通过利用BigInteger类及其isProbablePrime方法,可以高效地判断一个非常大的数是否为质数。这种方法适用于需要处理超长整数的情况。

979

被折叠的 条评论
为什么被折叠?



