Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Display all prime numbers upto N without sieve
#include<bits/stdc++.h> using namespace std; bool isPrime(int N){ if(N == 1) return false; int L = sqrt(N); for(int i = 2; i <= L; i++){ if(N%i == 0) return false; } return true; } int main() { int n; cin >> n; vector<int> prime; for(int i = 2; i <= n; i++){ if(isPrime(i)) { prime.emplace_back(i); } } cout << "List of Prime Numbers from 1 to " << n << ": \n"; for(int x: prime){ cout << x << " "; } return 0; }
run
|
edit
|
history
|
help
0
threadpool02
0/1Knapsack
CountingSort
Articulation Point
Connected components in complement graph
combine c++ string with dynamically allocated c array of chars through overloaded add operator
dsu on tree(264E BLOOD COUSIN RETURNS)
HashRK
Dar
xyz