We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9928541 commit 573ac84Copy full SHA for 573ac84
math/linear_sieve_ext.cpp
@@ -0,0 +1,43 @@
1
+#include <bits/stdc++.h>
2
+
3
+using namespace std;
4
5
+const int maxn = 10101010;
6
7
+int cnt[maxn], lp[maxn];
8
9
+void sieve(int n)
10
+{
11
+ vector<int> pr;
12
+ for (int i = 2; i <= n; i++) {
13
+ if (lp[i] == 0) {
14
+ cnt[i] = 1;
15
+ lp[i] = i;
16
+ pr.push_back(i);
17
+ }
18
19
+ for (int p : pr) {
20
+ if (p > lp[i] or p*i > n) break;
21
22
+ lp[p*i] = p;
23
24
+ if (i%p == 0) {
25
+ cnt[i*p] = cnt[i]+1;
26
27
+ else {
28
+ cnt[i*p] = 1;
29
30
31
32
+}
33
34
+int main()
35
36
+ int n;
37
+ cin >> n;
38
39
+ sieve(n);
40
41
+ for (int i = 1; i <= n; i++)
42
+ cout << i << " : " << lp[i] << "^" << cnt[i] << "\n";
43
0 commit comments