-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspf.sublime-snippet
More file actions
36 lines (35 loc) · 847 Bytes
/
spf.sublime-snippet
File metadata and controls
36 lines (35 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<snippet>
<content><![CDATA[
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 9;
int spf[N];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 2; i < N; i++) {
spf[i] = i;
}
for (int i = 2; i < N; i++) {
for (int j = i; j < N; j += i) {
spf[j] = min(spf[j], i);
}
}
int q; cin >> q; // queries q <= 1e6
while (q--) {
int n; cin >> n; // find prime factorization of n <= 1e6
vector<int> ans;
while (n > 1) {
ans.push_back(spf[n]);
n /= spf[n];
}
for (auto x: ans) cout << x << ' '; cout << '\n';
}
return 0;
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>spf</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.c++</scope>
</snippet>