Jump to content

User:Ledrug/bits: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
Line 88:
#define PBITS (MAX_PRIME * 8 / 30 + 1)
pint next_prime(pint);
int is_prime(pintxint);
void sieve(pint);
 
Line 126:
fwrite(pbits, 1, PBITS, fp);
fclose(fp);
}
 
int is_prime(xint x)
{
pint p;
if (x > 5) {
if (x < MAX_PRIME)
return pbits[x/30] & bit_pos[x % 30];
for (p = 2; p; p = next_prime(p))
if (x % p == 0) return 0;
return 1;
}
return x == 2 || x == 3 || x == 5;
}
 
Line 215 ⟶ 228:
init_primes();
 
whilefor ((p = next_prime(1; p)) < 6364; p++) {
po = (1LLU << p) - 1;
printf("2^%u - 1 = %llu = ", p, po);
fflush(stdout);
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.