請問一個數學問題??請問1~50萬有幾個質數?

2012-02-05 5:24 pm
1不是質數
請問1~50萬有幾個質數?
最接近50萬的植樹是多少?(可超過50萬)

回答 (3)

2012-02-07 3:58 am
✔ 最佳答案
#include <stdio.h>
#include <stdlib.h>int main()
{
int i,j,n,sum=0;
printf("Enter a number:\n");
scanf("%d",&n);

while(n<=0)
{
printf("Error!Please enter again!\n");
scanf("%d",&n);
}

for(i=2;i<n;i++)
{
for(j=2;j<i;j++)
{
if(i%j==0)
break;
}
if(i==j)
{
printf("%d ",i);
sum=sum+1;
}
}

printf("\nThere are %d prime numbers which are smaller than or equal to %d\n",sum,n);
system("pause");
return 0;
}

執行結果:
共有41538個質數小於或等於500000
最接近500000的質數是500009
參考: 自己
2012-02-05 6:17 pm
thanks
thanks
2012-02-05 6:11 pm
total is 41548. The closest is 500009. Next one is 499979.

2012-02-05 12:03:10 補充:
The correct number of primes is 41538. I have copied this wrong. Sorry for the confusion.


收錄日期: 2021-04-30 13:08:24
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20120205000016KK01745

檢視 Wayback Machine 備份