当前位置: 首页>>代码示例>>C++>>正文


C++ PrimeSieve类代码示例

本文整理汇总了C++中PrimeSieve的典型用法代码示例。如果您正苦于以下问题:C++ PrimeSieve类的具体用法?C++ PrimeSieve怎么用?C++ PrimeSieve使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PrimeSieve类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pushBack_N_Primes

    void pushBack_N_Primes(uint64_t n, uint64_t start)
    {
        n_ = n;
        PrimeSieve ps;
        std::size_t newSize = primes_.size() + static_cast<std::size_t>(n_);
        primes_.reserve(newSize);
        try
        {
            while (n_ > 0)
            {
                // choose stop > nth prime
                uint64_t logx = 50;
                uint64_t dist = n_ * logx + 10000;
                uint64_t stop = start + dist;

                // fix integer overflow
                if (stop < start)
                    stop = get_max_stop();

                ps.callbackPrimes(start, stop, this);
                start = stop + 1;

                if (stop >= get_max_stop())
                    throw primesieve_error("cannot generate primes > 2^64");
            }
        }
        catch (cancel_callback&) { }
    }
开发者ID:SChernykh,项目名称:Amicable,代码行数:28,代码来源:PushBackPrimes.hpp

示例2: primes

static PyObject* primes(PyObject* self, PyObject* args){
    Py_ssize_t start = 0, n = 0; size_t pi;
    if (!PyArg_ParseTuple(args, "n|n:primes", &start, &n)) return NULL;
    if (PyTuple_Size(args) == 1){
        n = start;
        start = 0;
    }
    if (start > n) return PyList_New(0);
    if (start < 2) start = 2;
    if (n < 3) return PyErr_Occurred() ? NULL : PyList_New(0);
    else if (n == 3){
        PyObject* just_two = PyList_New(1);
        PyList_SET_ITEM(just_two, 0, PyInt_FromLong(2));
        return just_two;
    }
    else if (n < 6)  pi = 2;
    else if (n < 8)  pi = 3;
    else if (n < 12) pi = 4;
    else if (n < 14) pi = 5;
    else if (n < 18) pi = 6;
    else             pi = n/(log(n)-1);
    size_t i = 0;
    PrimePyList primes(pi, &i);
    PrimeSieve ps;
    ps.generatePrimes(start, n-1, &primes);
    i--;
    while (i < --pi) PyObject_CallMethod(primes.list, (char*)"__delitem__", (char*)"(n)", pi);
    return primes.list;
}
开发者ID:hickford,项目名称:pyprimesieve,代码行数:29,代码来源:pyprimesieve.cpp

示例3: pushBackPrimes

 void pushBackPrimes(uint64_t start, uint64_t stop)
 {
     if (start <= stop)
     {
         std::size_t prime_count = approximate_prime_count(start, stop);
         primes_.reserve(primes_.size() + prime_count);
         PrimeSieve ps;
         ps.callbackPrimes(start, stop, this);
     }
 }
开发者ID:SChernykh,项目名称:Amicable,代码行数:10,代码来源:PushBackPrimes.hpp

示例4: main

int main(){
	
	//Initialize Seed
	srand(time (NULL) );	
	//Create Random Start from range 0 to 99
	int start = rand () % 99 + 1 ;
	//Create Random Stop from range 999 to 99999 (Nighty - Nine Thousand )	
	int stop =  rand () % 99999  + 999 ;
	
	cout<<"Random start "<<start <<endl;
	cout<<"Random end " <<stop <<endl;

	PrimeSieve ps;
	try
	{
		ps.generatePrimes(start ,stop ,callback);
	 //	ps.printPrimes(start ,stop );

	}catch (stop_primesieve & e  ){
	//cerr << " Error " << e.what() <<endl; 
	}
	//Random Number
	int  num1  =  rand() % 99 + 1 ; 	
	int  num2  =  rand() % 500 +  100;

	 //P and Q are 2 large random number
	long long unsigned  int  p = primes[num1];
	long long unsigned int  q = primes[num2];

	 //Calculate n
	long long unsigned int n = p * q;
	
	//Calculate phi
	long long unsigned int phi = (p -1 ) * (q -1);

	//Calculate e s.t. 
	
	cout << " num1 =	" << num1 <<endl;	
	cout << " num2 =	" << num2 <<endl;	
	cout << " p =	" << p <<endl;	
	cout << " q =	" << q <<endl;	
	cout << " n =	" << n <<endl;	
	cout << " phi =  "<< phi <<endl;	

	euclid(a,b);	

return 0;
}
开发者ID:santoshF,项目名称:RSA,代码行数:48,代码来源:RSA.cpp

示例5: pushBack_N_Primes

 void pushBack_N_Primes(uint64_t n, uint64_t start)
 {
   n_ = n;
   std::size_t newSize = primes_.size() + static_cast<std::size_t>(n_);
   primes_.reserve(newSize);
   PrimeSieve ps;
   try
   {
     while (n_ > 0)
     {
       uint64_t logn = 50;
       // choose stop > nth prime
       uint64_t stop = start + n_ * logn + 10000;
       ps.callbackPrimes(start, stop, this);
       start = stop + 1;
     }
   }
   catch (cancel_callback&) { }
 }
开发者ID:Bacteriaphage,项目名称:primesieve,代码行数:19,代码来源:PushBackPrimes.hpp

示例6: GetMultiplies

IntVec PrimeSwing::GetMultiplies( int _number, PrimeSieve& _sieve )
{
    IntVec multiplies;
    int sqrtN = static_cast<int>( sqrt( static_cast<double>(_number) ) );

    int maxIdx = _sieve.GetPrimeIndex( sqrtN, 2, _sieve.GetNumberOfPrimes() );
    for ( int i = 1; i < maxIdx; ++i )
    {
        int prime = _sieve.GetPrime(i);

        int q = _number, p = 1;

        while ((q /= prime) > 0)
            if ((q & 1) == 1)
                p *= prime;

        if (p > 1)
            multiplies.push_back(p);
    }

    int minIdx = maxIdx;
    maxIdx = _sieve.GetPrimeIndex( _number / 3, minIdx, _sieve.GetNumberOfPrimes() );

    for (int i = minIdx; i < maxIdx; ++i)
    {
        int prime = _sieve.GetPrime(i);

        if (((_number / prime) & 1) == 1)
            multiplies.push_back(prime);
    }

    return multiplies;
}
开发者ID:Shivanshu-Gupta,项目名称:fastfactorial,代码行数:33,代码来源:primeswing.cpp

示例7: Swing

mpz_class PrimeSwing::Swing( int _number, PrimeSieve& _sieve )
{
    // Small precalculated values
    if (_number < 33)
        return smallOddSwing[_number];

    // Fetch multiplies
    IntVec multiplies = GetMultiplies(_number, _sieve);

    // Return multiplies of primorials
    return _sieve.Primorial(_number / 2, _number) *
           UtilityFunctions::SequenceProduct( multiplies.begin(), multiplies.end() );
}
开发者ID:Shivanshu-Gupta,项目名称:fastfactorial,代码行数:13,代码来源:primeswing.cpp

示例8: primes_nth

static PyObject* primes_nth(PyObject* self, PyObject* args){
    Py_ssize_t n = 0;
    if (!PyArg_ParseTuple(args, "n:primes_nth", &n)) return NULL;
    if (n < 1){
        PyErr_SetString(PyExc_ValueError, "a positive integer is required");
        return NULL;
    }
    switch (n){
        case 1: return PyInt_FromLong(2);
        case 2: return PyInt_FromLong(3);
        case 3: return PyInt_FromLong(5);
        case 4: return PyInt_FromLong(7);
        case 5: return PyInt_FromLong(11);
    }
    NthPrime nthprime(n);
    PrimeSieve ps;
    try {
        ps.generatePrimes(0, n*log(n*log(n)), &nthprime);
    }
    catch (StopPrimeGeneration&) {}
    return nthprime.prime;
}
开发者ID:hickford,项目名称:pyprimesieve,代码行数:22,代码来源:pyprimesieve.cpp

示例9: count_sextuplets

uint64_t count_sextuplets(uint64_t start, uint64_t stop)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  return ps.countSextuplets(start, stop);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp

示例10: count_twins

uint64_t count_twins(uint64_t start, uint64_t stop)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  return ps.countTwins(start, stop);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp

示例11: nth_prime

uint64_t nth_prime(int64_t n, uint64_t start)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  return ps.nthPrime(n, start);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp

示例12: callback_primes

void callback_primes(uint64_t start, uint64_t stop, Callback<uint64_t>* callback)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  ps.callbackPrimes(start, stop, callback);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp

示例13: print_sextuplets

void print_sextuplets(uint64_t start, uint64_t stop)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  ps.printSextuplets(start, stop);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp

示例14: print_twins

void print_twins(uint64_t start, uint64_t stop)
{
  PrimeSieve ps;
  ps.setSieveSize(get_sieve_size());
  ps.printTwins(start, stop);
}
开发者ID:happyxerxes,项目名称:hello-world,代码行数:6,代码来源:primesieve-api.cpp


注:本文中的PrimeSieve类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。