http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1106
分析:
直接判断是不是素数
AC代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include<list>
#include <bitset>
#include <climits>
#include <algorithm>
#define gcd(a,b) __gcd(a,b)
#define mset(a,n) memset(a,n,sizeof(a))
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w",stdout)
typedef long long LL;
const LL mod=1e9+7;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
using namespace std;
int a[1005];
bool prime(int n){
if (n==2) return 1;
for (int i=2;i<=(int)sqrt(n);i++){
if (n%i==0) return 0;
}
return 1;
}
int main (){
int t;
cin>>t;
while (t--){
int n;
cin>>n;
if (prime(n)) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}