1029

来源:互联网 发布:淘宝定制的款去哪里了 编辑:程序博客网 时间:2024/05/24 01:40


Description

写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。

Input

一个数

Output

如果是素数输出prime 如果不是输出not prime

Sample Input

97

Sample Output

prime





#include <iostream>
#include<math.h>
using namespace std;
bool isp(int  x)
{
    if(x<2)
        return false;
    for(int i=2; i<=(int)sqrt((double)x); i++)
        if(x%i==0)
            return false;
    return true;

}
void slove()
{
    float a;
    while(cin>>a)
    {
        bool temp=false;
        temp=isp(a);
        if(temp)
            cout<<"prime"<<endl;
        else
            cout<<"not prime"<<endl;
    }
}
int main()
{
    slove();
    return 0;
}
0 0