fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin>>n;
  7. for(int i=2 ;i<=n;i++)
  8. {
  9. int count=0;
  10. for(int j=2;j<=i;j++)
  11. {
  12. if(i%j==0)
  13. count++;
  14. }
  15. if(count==1)
  16. {
  17. cout<<i<<endl;
  18. }
  19. }
  20. }
Success #stdin #stdout 0.01s 5468KB
stdin
9
stdout
2
3
5
7