The maximum network diameter for RSTP/MSTP is seven with default parameters.
Any size beyond that requires careful tweaking of the parameters, with the general caveat that you trade larger diameter for slower convergence. 17 switches are certainly possible but I seriously doubt 40.
RSTP and MSTP can support up to 40 switches
It’s not about the number of switches but about the diameter, the maximum number of hops between any two nodes. You can easily run a network of hundreds or even thousands of switches with a network diameter of five (at least in theory, that size would create other problems), e.g.
https://www.ciscopress.com/articles/article.asp?p=2202410&seqNum=4
Any STP variant creates one or more spanning trees on top of your physical network – that’s the most ‘natural’ topology for Ethernet (and most other L2 networks). Accordingly, your physical network should also form a tree. Do not design long chains or rings, they perform worse than a tree.
Why my switches don’t support/allow to use priority values more than 61440.
You don’t number your switches by priority. Instead, you configure your root bridge with priority 0, the backup root with 1, and leave the rest of the switches at default. Priority values are usually configured as multiples of 4096.