Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Math & Number Theory/Combinatorics mod p (nCr, Catalan, stars and bars)

Technique · CP 2000

Burnside's Lemma / Polya Counting

The number of objects distinct up to a symmetry group is the average, over the group, of the number of objects each symmetry fixes. For necklaces under rotation: (1/n) * sum over k of m^gcd(k, n).

Learn firstCombinatorics mod p (nCr, Catalan, stars and bars)GCD / LCM & EuclidBinary Exponentiation (fast power)
0%
mastery
0/2 solved
Practise nextCounting Necklaces
IdeaPracticePitfalls

Recognise it

The signal

count necklaces / grids up to rotation or reflection

  1. 1Brute force

    Generate every colouring and canonicalise it: m^n.

  2. 2The observation

    Counting orbits directly.

  3. 3Why it works

    Number of orbits = (1/|G|) * sum over g of |Fix(g)|.

Reach for it when

  • +'two colourings are the same if one is a rotation of the other'

Not when

  • ×no symmetry identification in the statement

Practice

Next

Counting Necklaces

0/2 solved
  • Counting NecklacesCSESHard
  • Counting GridsCSESHard

Pitfalls

Misconceptions

  • !dividing by |G| without a modular inverse
  • !forgetting reflections when flipping is allowed
Go deeperresources

Resources

  • Binary exponentiationcp-algorithms · article
  • Sieve of Eratosthenescp-algorithms · article
  • Modular inversecp-algorithms · article
  • DivisibilityUSACO Guide · course
  • CombinatoricsUSACO Guide · course
  • Math cheatsheetTech Interview Handbook · article
TodayReviewPatternsProblems