当前位置:网站首页>L1-028 judging prime number (10 points)

L1-028 judging prime number (10 points)

2022-07-04 07:29:00 Inter personal liabilities^

L1-028 Judgement primes (10 branch )

The goal of this question is very simple , Is to determine whether a given positive integer is a prime number .

Input format :
Enter a positive integer on the first line N(≤ 10), And then N That's ok , Each line gives a less than 2 31 A positive integer that needs to be judged .

Output format :
For each positive integer to be judged , If it's a prime , Output in one line Yes, Otherwise output No.

sample input :

2
11
111

sample output :

Yes
No

Test point 1:231, Must open long long Range ,1 Not primes , This is a special judgment , There is something wrong with this topic ,1 It should be neither prime nor prime

AC Code

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<sstream>

using namespace std;
typedef long long ll;
const int N=100010;

int main()
{
    
	int n;
	cin >> n;
	while(n -- )
	{
    
		ll x;
		cin >> x;
		bool flag = false;
		if(x == 1) flag = true;
		for(int i = 2; i < sqrt(x); i ++ )
		{
    
			if(x % i == 0)
			{
    
				flag = true;
				break;
			}
		}
		if(flag) cout << "No" << endl;
		else cout << "Yes" << endl;
	} 
	return 0;
}



原网站

版权声明
本文为[Inter personal liabilities^]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141533228134.html

随机推荐