Lucian_Adrian

#373 nprime

Oct 26th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n, y = 1, prim = 0;
  6. cin >> n;
  7. cout << "2 ";
  8. for(int i = 3 ; y < n ; i = i + 2){
  9. prim = 1;
  10. for(int d = 3; d * d <= i; d = d + 2)
  11. if(i % d == 0)
  12. prim = 0;
  13. if(prim == 1)
  14. cout << i << " ", y ++; }
  15. return 0;
  16. }
  17.  
Advertisement
Add Comment
Please, Sign In to add comment