c++ - Is this the fastest way and a new way to test special prime numbers? -
sample code:
bool is_special_prime (int n) { qhash<int, int> o; struct a_functor { int operator()(unsigned int n) { return n >> __builtin_ctz(n);} }a; int k = a(n + 1); if(k == 1) return 0; o[k] = k; int t = (n - 5) >> 1; for(int = 0; < t; i++) { k = a(n + k); if(k == 1 || o.contains(k)) return 0; o[k] = k; } return 1; } is way can test numbers greater latest largest prime 2 ^ 57885161 − 1?
have read lucas-lehmer? sounds have bit more study before you're finding new , faster ways test primes. try implementing lucas-lehmer bignum library first.
your algorithm iterates n/2, far being quick, it's in fact extremely slow indeed (much slower prime seive). never find prime bigger 2^32 or 2^64, quite bit less 2^57885161. see why it's slow? can't return 1 until it's looped on value of less n/2.
i haven't checked whether code accurately determines primes or not.
Comments
Post a Comment