Advertisement
am1x

tmp007.cpp

Oct 4th, 2023 (edited)
976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | Fixit | 0 0
  1. #include <stdio.h>
  2. #include <assert.h>
  3. #include <inttypes.h>
  4.  
  5.  
  6. bool is_prime(uint64_t x)
  7. {
  8.     if (x < 4)
  9.         return x >= 2;
  10.     if (x % 2 == 0)
  11.         return false;
  12.     for (uint32_t d = 3; d > 2; d += 2) {
  13.         uint64_t q = x / d;
  14.         uint32_t r = x % d;
  15.         if (q < d)
  16.             return true;
  17.         if (r == 0)
  18.             return false;
  19.     }
  20.     return true;
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.     for (int num = 1; num <= 1000000; num++) {
  27.         if (!is_prime(num))
  28.             continue;
  29.         printf("%d\n", num);
  30.     }
  31. #if 0
  32.     uint64_t x = 18446744073709551557ULL;
  33.     //uint64_t x = 1152921504606846883ULL;
  34.     bool q = is_prime(x);
  35.     printf("%llu %d \n", x, (int) q);
  36. #endif
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement