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


C++ PrimeSieve::generatePrimes方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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


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