C++ (Qt) const uint N = 1000000000; //миллиард QBitArray bbuf(N, false); bbuf[0] = 1; bbuf[1] = 1; for(uint s = 2; s < N; s++) { if(bbuf.at(s) == false) { for(uint j = s * 2; j < N; j += s) bbuf[j] = true; } }
C++ (Qt) const uint N = 1000000000/2; QBitArray bbuf(N, false); QTime t1 = QTime::currentTime(); uint k; for(uint i = 0; i < sqrt(N)+1; i++) { if(!bbuf.at(i)) { k = 2*i+3; for(uint j = k*(i+1)+i; j < N; j += k) bbuf[j] = true; } }
C++ (Qt)bbuf[j] = true;
C++ (Qt)#pragma omp parallel forfor (int thread = 0; thread < num_thread; ++thread) for (uint i = 0; i < N; ++i) if (!bbuf.at(i))
C++ (Qt)#pragma omp parallel for schedule(dynamic, 3)