File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change 1
1
#include < bits/stdc++.h>
2
2
#define rep (i,n ) for (int i = 0 ; i < (n); ++i)
3
3
using namespace std ;
4
- typedef long long ll;
4
+ using ll = long long ;
5
+ using P = pair<int ,int >;
5
6
6
7
int main () {
7
8
return 0 ;
You can’t perform that action at this time.
0 commit comments