fork download
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n, status = 1, num = 3, count, c;
  9.  
  10. cin >> n;
  11.  
  12. if ( n >= 1 )
  13. {
  14. cout << 2 << endl;
  15. }
  16.  
  17. for ( count = 2 ; count <=n ; )
  18. {
  19. for ( c = 2 ; c <= (int)sqrt(num) ; c++ )
  20. {
  21. if ( num%c == 0 )
  22. {
  23. status = 0;
  24. break;
  25. }
  26. }
  27. if ( status != 0 )
  28. {
  29. cout << num << " ";
  30. count++;
  31. }
  32. status = 1;
  33. num++;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0s 15232KB
stdin
5
stdout
2
3 5 7 11