Usually a given gear count and range has a certain defined sprocket set.
For example, 10sp 11-34 is 11-13-15-17-19-21-23-26-30-34.
Also 8sp 11-30 is 11-13-15-17-20-23-26-30.
Those are generally determined as being as close to the perfect geometric series as possible:
tooth_countn = tooth_count0 * (1+p)n
...but with the additional constraint that tooth count must be an integer.
For chainrings in a crankset, it should be easy to find all tooth counts. Those are almost always specified.
However, what you are planning to do is pointless. There's not point trying to know how many distinct gear ratios your bike has.
A bike doesn't have K distinct gears (unless it's a hub gear bike or a 1x derailleur bike).
A NxM derailleur bike has N partially overlapping ranges of M gears (where some combinations have excessive chain angle and should be avoided).
If you attempt to determine all distinct gear ratios, how on earth are planning to use that information on the fly? Determine quickly: you're on the 7th smallest gear combination (and a particular combination of that in case there are multiple configurations) and want to shift to the 9th smallest gear combination. What actions you need to take to reach the 9th smallest gear combination? Nobody can do that on the fly unless you have extraordinary memory.
Also if you list all gear combinations in ascending ratio order, you will get a series that makes no sense. It will NOT have a constant geometric progression. Some jumps are very minor, perhaps less than a percent. Other jumps may be over 10 percent. Some ratios are duplicated, occurring twice (or even three times!).
But if you use derailleur gears like you're supposed to use them, you may have 3 chainrings in front (28/38/48) and 8 sprockets in back (11-13-15-17-20-23-26-30). Then you can use:
- 28 tooth chainring with any of 15-17-20-23-26-30 (and maybe 13, that's a borderline case)
- 38 tooth chainring with any of 13-15-17-20-23-26 (and maybe 11 and 30, those are borderline cases)
- 48 tooth chainring with any of 11-13-15-17-20-23 (and maybe 26, that's a borderline case)
You also know that front shifts are slow and can't be done during full load but rear shifts can if you are skilled.
Then your aim is to analyze the needs caused by the terrain for long term to determine if you want to be on 28 tooth, 38 tooth or 48 tooth chainring, and then pick the correct rear sprocket for the short-term needs.
Also you have to remember that bigger chainrings waste less power because they are naturally used with bigger rear sprockets (sans chain angle considerations). Therefore, 48 tooth ring is preferable over 38 tooth ring which is preferable over 28 tooth ring, unless you anticipate needing low gear ratios before you have an opportunity to shift to a smaller ring.