You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <math.h>//使sqrt可以正常运行
|
|
|
|
|
int prime(int n)
|
|
|
|
|
{
|
|
|
|
|
int i ,m = 0;
|
|
|
|
|
if(n==0||n==1)//判断0和1的情况
|
|
|
|
|
return 0;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (i = 2; i <= sqrt(n); i++)//减少循环次数,原理为一个数不可能有比平方根大的因子
|
|
|
|
|
{
|
|
|
|
|
if (n%i == 0)
|
|
|
|
|
{
|
|
|
|
|
m++;//m不为0时说明n除了1和它本身之外还有别的因子,所以不是素数
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(m==0)
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int num = 0;
|
|
|
|
|
scanf("%d", &num);
|
|
|
|
|
if (prime(num))//调用prime函数
|
|
|
|
|
{
|
|
|
|
|
printf("Yes");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("No");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|