fork download
  1. #include <cstdio>
  2.  
  3. bool is_prime(int x) {
  4. if (x < 4) return (x == 2 or x == 3);
  5. if (x % 2 == 0 or x % 3 == 0) return false;
  6.  
  7. for (int i = 5; i * i <= x; i += 6)
  8. if ((x % i == 0) or (x % (i+2) == 0))
  9. return false;
  10. return true;
  11. }
  12.  
  13. int main() {
  14. int bound;
  15. while (scanf("%d", &bound) == 1) {
  16. printf("Primes less than %d :", bound);
  17. for (int i = 0; i < bound; ++i)
  18. if (is_prime(i))
  19. printf(" %d", i);
  20. printf("\n");
  21. }
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 3464KB
stdin
100
stdout
Primes less than 100 : 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97