This problem was really fun, but mathematically the most challenging problem so far.
I learnt the Cauchy-Frobenius Lemma in Abstract Algebra last semester, and I can without a doubt say it's the most confusing topic i've ever done, but I knew it would be perfect for this problem.
I brushed up on the Pólya enumeration theorem again, and managed to to find out that I was trying to solve was a subset of a problem involving what is referred to as a Necklace in Combinatorics. This page had an explicit formula which is stronger than what actually we need.
Enter a number (yourinput)
Code will output sum of all f(m, n) such that f(m, n) ≤ yourinput