> 其他 >
怎么证明一个数为质数
人气:488 ℃ 时间:2020-04-09 00:48:06
解答
C++代码
int main()
{
const int max =100;
long primes[max] = {2,3,5 };
long trial = 5;
int count =3;
int found =0;
do
{
trial +=2;
for(int i=0;i< count;i++)
{
found = (trial % *(primes + i)) == 0;
if(found)
break;
}
if(found == 0)
*(primes + count++) = trial;
}while(count < max);
return 0;
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版