0
点赞
收藏
分享

微信扫一扫

51nod-1186 质数检测

Mhhao 2023-06-12 阅读 68


原题链接



1186 质数检测 V2



基准时间限制:1 秒 空间限制:131072 KB 分值: 40  难度:4级算法题



 收藏

 关注


Input


输入一个数N(2 <= N <= 10^30)


Output


如果N为质数,输出"Yes",否则输出"No"。


Input示例


17


Output示例


Yes



boolean isPrime=aBigInteger.isprobablePrime(alpha); 
//false:  this BigInteger is 100% not prime 
//true: this BigInteger may be a prime, the probability is larger
//than (1-1/20)=95%.
//the larger the alpha, the longer the calculation time will be.

import java.util.*;
import java.math.*;
public class TEST {
   
	public static void main(String args[]){
		
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			BigInteger m = cin.nextBigInteger();
			if(m.isProbablePrime(1)){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}
	}
}



举报

相关推荐

0 条评论