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.
Function/素数.cpp

42 lines
729 B

3 years ago
#include <stdio.h>
#include <math.h>//ʹsqrt<72><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int prime(int n)
{
int i ,m = 0;
if(n==0||n==1)//<2F>ж<EFBFBD>0<EFBFBD><30>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>
return 0;
else
{
for (i = 2; i <= sqrt(n); i++)//<2F><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>Ϊһ<CEAA><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if (n%i == 0)
{
m++;//m<><6D>Ϊ0ʱ˵<CAB1><CBB5>n<EFBFBD><6E><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
if(m==0)
{
return 1;
}
else
{
return 0;
}
}
}
int main()
{
int num = 0;
scanf("%d", &num);
if (prime(num))//<2F><><EFBFBD><EFBFBD>prime<6D><65><EFBFBD><EFBFBD>
{
printf("Yes");
}
else
printf("No");
return 0;
}