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;
#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;
}
0 0
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- 1029
- problem 1029
- hdu 1029
- Ural 1029
- sicily 1029
- zoj 1029
- hdu 1029
- HDU 1029
- poj 1029
- hdu 1029
- 常见的安全算法
- hdu 1166 敌兵布阵
- 自定义dialog and anim
- environ是在哪儿里定义的?
- 【开源Linux学习笔记001 初识CentOS】
- 1029
- Spring-6,配置bean的集合属性
- Tensorflow实例-CNN处理句子相似度(MPCNN)
- C语言实现栈
- 开通博客第一天
- Apache的三种MPM模式比较:prefork,worker,event
- 孙鑫 笔记
- priority_queue的底层实现及数组建堆。
- TensorFlow基本用法