Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <assert.h>
- #include <inttypes.h>
- bool is_prime(uint64_t x)
- {
- if (x < 4)
- return x >= 2;
- if (x % 2 == 0)
- return false;
- for (uint32_t d = 3; d > 2; d += 2) {
- uint64_t q = x / d;
- uint32_t r = x % d;
- if (q < d)
- return true;
- if (r == 0)
- return false;
- }
- return true;
- }
- int main()
- {
- for (int num = 1; num <= 1000000; num++) {
- if (!is_prime(num))
- continue;
- printf("%d\n", num);
- }
- #if 0
- uint64_t x = 18446744073709551557ULL;
- //uint64_t x = 1152921504606846883ULL;
- bool q = is_prime(x);
- printf("%llu %d \n", x, (int) q);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement