Description
写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。
Input
一个数
Output
如果是素数输出prime 如果不是输出not prime
Sample Input
97
Sample Output
prime
#include <iostream>
#include<math.h>
using namespace std;
#include<math.h>
using namespace std;
bool isp(int x)
{
if(x<2)
return false;
{
if(x<2)
return false;
for(int i=2; i<=(int)sqrt((double)x); i++)
if(x%i==0)
return false;
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;
}
{
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;
}
int main()
{
slove();
return 0;
}