判断素数

master
p5tblxgmk 3 years ago
parent 9a1c2be534
commit f403d39d40

@ -0,0 +1,41 @@
#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;
}
Loading…
Cancel
Save