Just replace
constexpr int ans
with int ans
? Function params are never considered to be constexpr inside of the said function. (But its return value can't be constexpr if everything it does is possible to do at compile-time.)