快速质数判断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
bool checkSix(const int num) {
unsigned int i, half;
if (num <= 1)
return 0;
if (num == 2 || num == 3)
return 1;
else if (num % 6 != 1 && num % 6 != 5)
return 0;
half = (unsigned int)sqrt(num);
for (i = 5; i <= half; i += 6) {
if (num % i == 0 || num % (i + 2) == 0)
return 0;
}
return 1;
}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!