Guest User

Untitled

a guest
Dec 16th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int main(void)
  5. {
  6. ofstream out("1.txt");
  7. int n,i,k,b,l;
  8. cin>>n;
  9. int a[n];
  10. bool pr=true;
  11. k=0;
  12. b=2;
  13. l=1;
  14. while (b<n){
  15. pr=true;
  16. if ((l+1)*(l+1)<=b)
  17. l++;
  18. for (i=0;(i<k)&&(a[i]<=l);i++)
  19. if (b%a[i]==0){
  20. pr=false;
  21. break;
  22. }
  23. if (pr){
  24. out<<b<<endl;
  25. a[k++]=b;
  26. }
  27. b++;
  28. }
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment