#include #include #include static unsigned S2(unsigned x, unsigned yin); #define cache_size 65536 int f_cache[cache_size]; static unsigned JSHpi1(unsigned xin) { // cache most common answers if (xin yin) return sum; int tmp2 = x / 2; if (2 < tmp2) a3 = tmp2 - S2 (tmp2, 2) - 1; else a3 = JSHpi1 (tmp2); sum += a3; if (9 <= yin) sum += compute_sum (3, x); if (25 <= yin) sum += compute_sum (5, x); for (i=6; ; i+=6) { j = i + 1; if (j*j > yin) return sum; sum += compute_sum (j, x); j = i + 5; if (j*j > yin) return sum; sum += compute_sum (j, x); } } unsigned long long pi(unsigned long long x) { for(int i = 0; i < cache_size; i++) f_cache[i] = -1; return JSHpi1(x); }