Ϊʲô˫ѻ·ÖÐ k = sqrt(m) ¶¨ÒåÔÚµÚÒ»¸öÑ»·ºó³ÌÐò²ÅÕý³£ÔËÐÐ
#include <stdio.h>#include <math.h>
void main()
{
int m, k ,i;
for (m = 100;m <=200;m++)
{
k = sqrt(m);
for(i = 2;i <= k;i++)
{
if (m%i == 0)
{
break;
}
}
if (i > k)
{
printf("%d\n",m);
}
else if
{
continue;
}
}
}
Èç¹ûk = sqrt(m)¶¨ÒåÔÚµÚÒ»¸öÑ»·Ç°»á³öÏÖ´íÎó£¬ÕâÊÇΪʲô£¿Çó½â´ð£¡ µÚÒ»¸öÑ»·Ç°£¬ÄÇÎÒÇëÎÊ£¬ÄãµÄ m = £¿ ÒòΪÄãmµÄÖµÔÚ½øÈëµÚÒ»¸öÑ»·µÄʱºò²Å±»¸³Ó裬ÔÚ½øÈë֮ǰʹÓÃsqrt(m)º¯Êý´«ÈëµÄ²ÎÊýmÊÇδ³õʼ»¯µÄ¡£
Ò³:
[1]