提交 c1000709 编写于 作者: 独孤过's avatar 独孤过

优化代码

上级 603b127d
......@@ -4,11 +4,13 @@
bool prime(unsigned natural)
{
if (natural <= 1)
if (natural == 2)
return true;
if (natural < 2 || natural % 2 == 0)
return false;
for (unsigned factor = 2, \
for (unsigned factor = 3, \
limit = (unsigned)floor(sqrt(natural)); \
factor <= limit; ++factor)
factor <= limit; factor += 2)
if (natural%factor == 0)
return false;
return true;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册