暂时没有时间整理,先放在这里:

http://www.quora.com/Prime-Numbers/What-are-good-ways-to-find-nth-prime-number-in-the-fastest-way

—————————————————————————————————————————————————————————————————————

. So if you're searching for the nth prime, I'd look in this gap.

——————————————————————————————————————————————————————————————————————

http://primes.utm.edu/nthprime/a...
  

———————————————————————————————————————————————————————————————————————

附上一个同学写的用bitarray实现的http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes求素数的方法:

/*
 * ========================================================================
 *
 *       Filename:  bitset.h
 *
 *    Description:  bitset implementation in c.
 *
 *        Created:  05/27/2013 11:09:43 PM
 *
 *         Author:  Fu Haiping (forhappy), haipingf@gmail.com
 *        Company:  ICT ( Institute Of Computing Technology, CAS )
 *
 * ========================================================================
 */
#include <limits.h>     /* for CHAR_BIT */

#define BITMASK(b) (1 << ((b) % CHAR_BIT))
#define BITSLOT(b) ((b) / CHAR_BIT)
#define BITSET(a, b) ((a)[BITSLOT(b)] |= BITMASK(b))
#define BITCLEAR(a, b) ((a)[BITSLOT(b)] &= ~BITMASK(b))
#define BITTEST(a, b) ((a)[BITSLOT(b)] & BITMASK(b))
#define BITNSLOTS(nb) ((nb + CHAR_BIT - 1) / CHAR_BIT)
/* 
 * char bitarray[BITNSLOTS(47)];
 * BITSET(bitarray, 23);
 * if(BITTEST(bitarray, 35)) ...
 *
 * */

#include <stdio.h>
#include <string.h>

#define MAX 10000

int main()
{
    char bitarray[BITNSLOTS(MAX)];
    int i, j;

    memset(bitarray, 0, BITNSLOTS(MAX));

    for(i = 2; i < MAX; i++) {
        if(!BITTEST(bitarray, i)) {
            printf("%d\n", i);
            for(j = i + i; j < MAX; j += i)
                BITSET(bitarray, j);
        }
    }
    return 0;
}

 

 

 

相关文章:

  • 2021-11-02
  • 2021-08-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2022-03-07
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-10-27
  • 2021-06-22
相关资源
相似解决方案