8000 add prime, change typedef to using · atcoder/live_library@9997e88 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9997e88

Browse files
author
atcoder-live
committed
add prime, change typedef to using
1 parent 12465a6 commit 9997e88

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

prime.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Sieve of Eratosthenes
2+
// https://youtu.be/UTVg7wzMWQc?t=2774
3+
struct Sieve {
4+
int n;
5+
vector<int> f, primes;
6+
Sieve(int n=1):n(n), f(n+1) {
7+
f[0] = f[1] = -1;
8+
for (ll i = 2; i <= n; ++i) {
9+
if (f[i]) continue;
10+
primes.push_back(i);
11+
f[i] = i;
12+
for (ll j = i*i; j <= n; j += i) {
13+
if (!f[j]) f[j] = i;
14+
}
15+
}
16+
}
17+
bool isPrime(int x) { return f[x] == x;}
18+
vector<int> factorList(int x) {
19+
vector<int> res;
20+
while (x != 1) {
21+
res.push_back(f[x]);
22+
x /= f[x];
23+
}
24+
return res;
25+
}
26+
vector<P> factor(int x) {
27+
vector<int> fl = factorList(x);
28+
if (fl.size() == 0) return {};
29+
vector<P> res(1, P(fl[0], 0));
30+
for (int p : fl) {
31+
if (res.back().first == p) {
32+
res.back().second++;
33+
} else {
34+
res.emplace_back(p, 1);
35+
}
36+
}
37+
return res;
38+
}
39+
};

template.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#include <bits/stdc++.h>
22
#define rep(i,n) for (int i = 0; i < (n); ++i)
33
using namespace std;
4-
typedef long long ll;
4+
using ll = long long;
5+
using P = pair<int,int>;
56

67
int main() {
78
return 0;

0 commit comments

Comments
 (0)
0