File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,5 @@ mu[i] = {0 if i contains a prime more than once
22 1 if i consists of even number of primes
33 -1 otherwise, ie. odd number of primes}
44mu can be used to count number of things with gcd of 1 using inclution exclution
5+ to do this: sigma_over_possible_j_as_product_of_primes(mu[j] * f(j))
6+ where f(j) returns number of things where their gcd is divisible by every elemnt of j's factorization, ie. 'j'.
Original file line number Diff line number Diff line change @@ -60,8 +60,12 @@ sieve(10000000); // can go up to 10^7 (need few seconds)
6060* O(log10 n): `n = max(a, b)`
6161
6262```cpp
63- int gcd(int a, int b) {
64- return b == 0 ? a : gcd(b, a % b);
63+ long long gcd(long long a, long long b) {
64+ while (a > 0 && b > 0) {
65+ if (a > b) a %= b;
66+ else b %= a;
67+ }
68+ return a + b;
6569}
6670int lcm(int a, int b) {
6771 return a * (b / gcd(a, b));
You can’t perform that action at this time.
0 commit comments