题目7:找出第10001个质数。
前六个质数是2,3,5,7,11和13,其中第6个是13.
第10001个质数是多少?
源码
STDMETHODIMP COuLa::Test7(int number) { // TODO: 在此添加实现代码 int iNumberForCout = 1; int iNumberForOutput = 0; int iNumberForAdd = 1; while(iNumberForCout<number) { iNumberForAdd++; iNumberForOutput = iNumberForAdd*2 - 1; for(int i = 2; i<iNumberForOutput; i++) { if(iNumberForOutput%i == 0) { break; } if(i == iNumberForOutput-1) iNumberForCout++; } } printf("The Test 7 Number is %d.\n",iNumberForOutput); return S_OK; }
函数调用
#define TEST7_NUMBER 10001 IOula->Test7(TEST7_NUMBER);
输出
The Test 7 Number is 104743.
时间: 2024-10-05 21:23:42