#include
#include
#include
#include
#define st 7
#define move 4
#define blocksize (30030 * 17 * 2) // 2 * 3 * 5 * 7 * 11 * 13 * 17 = 510510
#define maxm ((blocksize >> move) + 1)
#define set_bit(a, n) a[n >> 3] |= (1 << (n & 7))
typedef unsigned int uint;
typedef unsigned char uchar;
static uint prime[6800];
static uchar basetpl[maxm * 2];
static uchar numbit0[1 << 8];
static const uint maxn = (-1u / 2);
static int sieve( )
}return primes;
}static void initbit( )
static void inline
crossoutfactormod6(uchar bitarray, const uint start,
const uint leng, uint factor)
;const char mrid = ((start + s1) / factor) % 6 - 1;
s1 = s1 / 2 + skip[mrid] * factor;
s2 = s1 + skip[mrid + 1] * factor;
for (factor += 2 * factor; s2 <= leng / 2; )
if (s1 <= leng / 2)
set_bit(bitarray, s1);;
}static int segmentederatosieve(uint start, int leng)
int countprimes(uint start, uint stop)
int main(int argc, char* argv)
return 0;
}//pi[1, 2147483647] = 105097565, time use 1592 ms
//
素數篩法系列之3 減少篩次數
篩法加速 接上一節,篩某個素數的倍數的時候只需篩掉奇數倍數,這樣計算量可 可減少一般,再進一步優化,不篩3的倍數,只篩6k 1,6k 5 之類素數,計算量只有原來2 3.static void crossoutfactormod6 uchar bitarray,const uint64 start,...
篩選素數之尤拉篩法 python實現 附帶證明
返回型別 列表 說明 返回小於upperbound的所有素數 def oulashai upperbound filter false for i in range upperbound 1 primenumbers for num in range 2,upperbound 1 if not fi...
演算法系列 演算法入門之遞迴分而治之思想的實現
別想太多,肯定要!你以為的演算法是各種排序,選擇排序 快速排序 歸併排序,廣深搜尋 動態規劃.然而,演算法實際上指的是解決某個實際問題的方法。解決同乙個問題的方法有很多,比如迴圈輸出某個陣列,可以有for for in for of map foreach等,不同的實現方法會反映不同的效能,這些效能...