void GeneratePrimeTable() { const unsigned int nDefaultSieveExt = (fTestNet) ? nDefaultSieveExtensionsTestnet : nDefaultSieveExtensions; nSieveExtensions = (unsigned int)GetArg("-sieveextensions", nDefaultSieveExt); nSieveExtensions = std::max(std::min(nSieveExtensions, nMaxSieveExtensions), nMinSieveExtensions); nSievePercentage = (unsigned int)GetArg("-sievepercentage", nDefaultSievePercentage); nSievePercentage = std::max(std::min(nSievePercentage, nMaxSievePercentage), nMinSievePercentage); nSieveSize = (unsigned int)GetArg("-sievesize", nDefaultSieveSize); nSieveSize = std::max(std::min(nSieveSize, nMaxSieveSize), nMinSieveSize); printf("GeneratePrimeTable() : setting nSieveExtensions = %u, nSievePercentage = %u, nSieveSize = %u\n", nSieveExtensions, nSievePercentage, nSieveSize); const unsigned nPrimeTableLimit = nSieveSize; vPrimes.clear(); // Generate prime table using sieve of Eratosthenes std::vector<bool> vfComposite (nPrimeTableLimit, false); for (unsigned int nFactor = 2; nFactor * nFactor < nPrimeTableLimit; nFactor++) { if (vfComposite[nFactor]) continue; for (unsigned int nComposite = nFactor * nFactor; nComposite < nPrimeTableLimit; nComposite += nFactor) vfComposite[nComposite] = true; } for (unsigned int n = 2; n < nPrimeTableLimit; n++) if (!vfComposite[n]) vPrimes.push_back(n); printf("GeneratePrimeTable() : prime table [1, %u] generated with %u primes\n", nPrimeTableLimit, (unsigned int) vPrimes.size()); }
void GeneratePrimeTable(unsigned int nSieveSize) { const unsigned int nPrimeTableLimit = nSieveSize ; vPrimes.clear(); // Generate prime table using sieve of Eratosthenes std::vector<bool> vfComposite (nPrimeTableLimit, false); for (unsigned int nFactor = 2; nFactor * nFactor < nPrimeTableLimit; nFactor++) { if (vfComposite[nFactor]) { continue; } for (unsigned int nComposite = nFactor * nFactor; nComposite < nPrimeTableLimit; nComposite += nFactor) { vfComposite[nComposite] = true; } } for (unsigned int n = 2; n < nPrimeTableLimit; n++) { if (!vfComposite[n]) { vPrimes.push_back(n); } } printf("GeneratePrimeTable() : prime table [1, %d] generated with %lu primes\n", nPrimeTableLimit, vPrimes.size()); vPrimesSize = vPrimes.size(); }
void GeneratePrimeTable() { vPrimes.clear(); // Generate prime table using sieve of Eratosthenes std::vector<bool> vfComposite (nPrimeTableLimit, false); for (unsigned int nFactor = 2; nFactor * nFactor < nPrimeTableLimit; nFactor++) { if (vfComposite[nFactor]) continue; for (unsigned int nComposite = nFactor * nFactor; nComposite < nPrimeTableLimit; nComposite += nFactor) vfComposite[nComposite] = true; } for (unsigned int n = 2; n < nPrimeTableLimit; n++) if (!vfComposite[n]) vPrimes.push_back(n); printf("GeneratePrimeTable() : prime table [1, %u] generated with %u primes\n", nPrimeTableLimit, (unsigned int) vPrimes.size()); }
void GeneratePrimeTable() { //nSievePercentage = (unsigned int)GetArg("-sievepercentage", nDefaultSievePercentage); nSievePercentage = globalconfs.coin.config.GetValue<uint>("sievepercentage"); nSievePercentage = std::max(std::min(nSievePercentage, nMaxSievePercentage), nMinSievePercentage); //nSieveSize = (unsigned int)GetArg("-sievesize", nDefaultSieveSize); nSieveSize = globalconfs.coin.config.GetValue<uint>("sievesize"); nSieveSize = std::max(std::min(nSieveSize, nMaxSieveSize), nMinSieveSize); printf("GeneratePrimeTable() : setting nSievePercentage = %u, nSieveSize = %u\n", nSievePercentage, nSieveSize); const unsigned nPrimeTableLimit = nSieveSize; vPrimes.clear(); // Generate prime table using sieve of Eratosthenes std::vector<bool> vfComposite (nPrimeTableLimit, false); for (unsigned int nFactor = 2; nFactor * nFactor < nPrimeTableLimit; nFactor++) { if (vfComposite[nFactor]) continue; for (unsigned int nComposite = nFactor * nFactor; nComposite < nPrimeTableLimit; nComposite += nFactor) vfComposite[nComposite] = true; } for (unsigned int n = 2; n < nPrimeTableLimit; n++) if (!vfComposite[n]) vPrimes.push_back(n); printf("GeneratePrimeTable() : prime table [1, %d] generated with %lu primes", nPrimeTableLimit, vPrimes.size()); //BOOST_FOREACH(unsigned int nPrime, vPrimes) // printf(" %u", nPrime); printf("\n"); const unsigned int nPrimes = vPrimes.size(); vTwoInverses = std::vector<unsigned int> (nPrimes, 0); for (unsigned int nPrimeSeq = 1; nPrimeSeq < nPrimes; nPrimeSeq++) { vTwoInverses[nPrimeSeq] = int_invert(2, vPrimes[nPrimeSeq]); } }