素数判定

/*
* Copyright (c) 2016, 安徽大学计算机科学与技术学院
* All rights reserved.
* 作 者:  杨磊
* 完成日期:2016 年 12 月 27 日
* 问题描述:判断一个数是不是素数。
*/
#include<cstdio>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
int IsPrime(int t){
    int i,flag=1;
    for(i=2;i*i<=t;i++)
        if(t%i==0)
           flag=0;
    return(flag);
}
int main(){
      int a;
      while(scanf("%d",&a)!=EOF)
      if(IsPrime(a))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
return 0;}

posted @ 2016-12-28 15:38  Super___Yang  阅读(134)  评论(0)    收藏  举报