Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int main(void)
- {
- ofstream out("1.txt");
- int n,i,k,b,l;
- cin>>n;
- int a[n];
- bool pr=true;
- k=0;
- b=2;
- l=1;
- while (b<n){
- pr=true;
- if ((l+1)*(l+1)<=b)
- l++;
- for (i=0;(i<k)&&(a[i]<=l);i++)
- if (b%a[i]==0){
- pr=false;
- break;
- }
- if (pr){
- out<<b<<endl;
- a[k++]=b;
- }
- b++;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment