I???ll skip describing how exactly this works since we???ll be content to deal directly with the factored rational function form of our generating functions from here on out; if you want more details (and see just how useful the notion of a generating function turns out to be for all kinds of problems!), I recommend you look at the excellent ???Concrete Mathematics??? by Graham, Knuth and Patashni