fork download
  1. #include <stdio.h>
  2.  
  3. int laNguyenTo(int x) {
  4. if (x < 2) return 0;
  5. for (int i = 2; i * i <= x; i++) {
  6. if (x % i == 0) return 0;
  7. }
  8. return 1;
  9. }
  10.  
  11. int main() {
  12. int n;
  13. scanf("%d", &n);
  14. for (int i = 2; i < n; i++) {
  15. if (laNguyenTo(i)) {
  16. printf("%d\n", i);
  17. }
  18. }
  19. return 0;
  20. }
Success #stdin #stdout 0s 544KB
stdin
10
stdout
2
3
5
7