A network Meta Stack Exchange site search comes up with the related Logic Behind StackOverflow Question IDs, with Robert Cartaino's answer stating
Stack Overflow uses one table to hold both questions and answers. The ID is the primary key in the table called
Posts. The ID is incremented each time a question or answer is posted.
Note this is for Stack Overflow's site, but this site would have a similar table and associated behavior. Also, the question and original answer are from early $2010$ (unfortunately, I've not been able to find anything more recent), but I believe it's likely still accurate. Regardless, since it's from not too long before when your example posts were written, this situation likely specifically applies to them, even if things have been changed later (e.g., more recent question and answer IDs are now in separate tables). It seems the site's software bypasses the "questions" part of the URL and, instead, uses that ID to show the answer with the corresponding ID. Nonetheless, it does this with a special format, e.g.,
https://math.stackexchange.com/questions/29/can-you-recommend-a-decent-online-or-software-calculator/47#47 for your first example. This is likely to indicate that it's showing something different than what was actually explicitly requested.
Whether or not the site should behave this way, or if it should instead show something like a $404$ error, is debatable. Although I appreciate that the software tries to handle the request in a fairly reasonable fashion, I also would prefer to get an error instead since the displayed result is not what I actually asked for, not to mention that showing an unrelated answer instead is somewhat confusing. Nonetheless, as indicated in Martin Sleziak's comment, it's likely better to maintain backwards compatibility with any existing links using this behavior than changing it now.