Maybe invest in a utility function here:

std::wstring Foo(const int exponent, const wchar* name) {
  return exponent != 0 ? L" " + name + L"^" + std::to_wstring(exponent) : L"";
}

and in fact this function could also take care of exponent == 1 to return "m" instead of "m^1".