Editorial for Dãy số nguyên tố


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
#include <bits/stdc++.h>
using namespace std;

int prime(int n){
    int dem = 0;
    for(int i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            ++dem;
            if(i != n / i){
                ++dem;
            }
        }
    }
    if(dem == 2){
        return 1; // true
    }
    else{
        return 0; // false;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i = 1; i <= n; i++){
        if(prime(i) == 1){
            printf("%d ", i);
        }
    }
    return 0;
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.