Created
April 11, 2023 18:10
-
-
Save NamPE286/ba67206a726d7b0d5b8c3eb253537ac1 to your computer and use it in GitHub Desktop.
Prime factorization with sieve of Eratosthenes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
vector<vector<ll>> sieve(ll n){ | |
vector<vector<ll>> fact(n + 1); | |
for(ll i = 2; i <= n; i++){ | |
if(fact[i].empty()){ | |
for(ll j = i; j <= n; j += i){ | |
fact[j].push_back(i); | |
} | |
} | |
} | |
return fact; | |
} | |
int main(){ | |
auto fact = sieve(4); | |
for(ll i : fact[4]) cout << i << ' '; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment