templates/burnsides-lemma.cpp
compilable
$cat templates/burnsides-lemma
Burnside's Lemma
Count distinct objects under symmetry (rotations) using Burnside's lemma.
#burnside#counting#symmetry#necklace#group-theory
Log in to track progress, save custom versions, and organize into collections.Log In
$cat source_code/
cpp
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
ll power(ll base, ll exp, ll mod) {
ll res = 1; base %= mod;
while (exp > 0) {
if (exp & 1) res = res * base % mod;
base = base * base % mod;
exp >>= 1;
}
return res;
}
ll modInv(ll x) { return power(x, MOD - 2, MOD); }
ll necklaceCount(ll n, ll k) {
ll ans = 0;
for (ll i = 1; i <= n; i++)
ans = (ans + power(k, __gcd(i, n), MOD)) % MOD;
return ans % MOD * modInv(n) % MOD;
}24 linesutf-8
$cat explanation_notes.md
notes_viewer --renderedmarkdown (math enabled)
Burnside's Lemma
Counts distinct objects under a group action (e.g., rotational symmetry).
Formula
where is the set of elements fixed by group element .
Necklace Application
For beads with colors, considering only rotational symmetry:
Rotating by positions fixes colorings.