题解 | 素数判断

素数判断

https://www.nowcoder.com/practice/5ab1b9690af047699e96c87dee65def4

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
 Scanner sc = new Scanner(System.in);
                int n=sc.nextInt();
                int count=0;
                for(int i = 1; i <= n; i++){
                    int a = sc.nextInt();
                    if(a<=1){
                        count++;
                    }
                    if(a==2){count=0;}
                    for(int j=2;j<a;j++){

                        if(a%j==0){
                            count++;
                        }
                        if(count>0){
                            break;
                        }
                    }
                    if(count==0){
                        System.out.println("Yes");
                    }else{ System.out.println("No");}
                    count=0;
                }

       
    }
}






全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务