/*
对于大于等于5的数字,我们可以用6的倍数来表示它,
即,6x-1, 6x, 6x+1, 6x+2, 6x+3, 6x+4的轮回;
6x+2 = 2(3x+1), 6x+3 = 3(2x+1), 6x+4 = 2(3x+2), 6x显然这些
并不是素数;那么,我们可以总结为,对4以上的数字来说,
只有6的倍数的左右两位才有可能是素数;
作者:金七木
链接:https://www.jianshu.com/p/395248fd2c47
來源:简书
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
*/
#include <stdio.h>
#include <math.h>
int prime( int x )
{
if(x <= 1)
return 0;
if( x == 2 || x == 3 || x == 5 )
return 1;
if( x%2 == 0 || x%3 == 0 ) /*判断是否为2,3的倍数*/
return 0;
for(int i=6; i<=sqrt(x); i += 6 ){
if( x % (i-1) == 0 || x % (i+1) == 0 )
return 0;
}
return 1;
}
int main()
{
int number;
while(scanf("%d", &number ) != EOF)
{
if( prime( number ) )
printf("Yes\n");
else
printf("No\n");
}
return 0;
}