Project Euler__problem 7

Problem 7


10001st prime

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?


第10001個素數

列出前6個素數,它們分別是2、3、5、7、11和13。我們可以看出,第6個素數是13。

第10,001個素數是多少?


最近這段時間都很忙,一直沒什麼機會去做PE了

趁着有空的時間,臨急臨忙刷了第7題

感覺上還是有點複雜,不會簡單的算法。


#include<iostream>  

int zhishu(int num)
{
	int i;
	for (i = num / 2; i > 1; i--)
		if (num%i != 0)
			continue;
		else
			break;
	if (i == 1)
		return true;
	else
		return false;
}
void main()
{
	int number=2,cout=0;
	for (;; number++)
		if (zhishu(number))
		{
			cout++;
			if (cout == 10001)
				break;
		}
	std::cout <<"第10001個質數是"<< number << std::endl;
	system("pause");
}

最後得出的結果是104743


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章