Primes in practice by seeking the sieve # N # Bridge Cup Blue

Here Insert Picture Description

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int a[10005];
char b[10005];
int main()
{
    int n;
    while(cin>>n){
        int flag=1;
        for(int i=2;i<=n;i++){
            flag=1;
            for(int j=2;j<i;j++){
                if(i%j==0) flag=0;
            }
            if(flag) cout<<i<<endl;
        }
    }
    return 0;
}
Published 137 original articles · won praise 8 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_43476037/article/details/104009595