Language: C++

#include <cassert>
#include <cstdint>
#include <limits>

class montgomery_fp {
  using Self = montgomery_fp;

  using u64 = std::uint64_t;
  using u32 = std::uint32_t;
  using i32 = std::int32_t;

  static u32 mod;
  static u32 inv;
  static u32 r2;

  static u32 reduce(const u64 x) noexcept {
    const u32 y = u32(x >> 32) - u32(u64(u32(x) * inv) * mod >> 32);
    return i32(y) < 0 ? y + mod : y;
  }

  u32 v;

public:
  montgomery_fp(const u32 x = 0) noexcept : v(reduce(u64(x) * r2)) {}

  u32 get() const noexcept { return reduce(v); }

  Self operator+(const Self r) const noexcept { return Self(*this) += r; }
  Self operator-(const Self r) const noexcept { return Self(*this) -= r; }
  Self operator*(const Self r) const noexcept { return Self(*this) *= r; }
  Self operator/(const Self r) const noexcept { return Self(*this) /= r; }

  Self &operator+=(const Self r) noexcept {
    v += r.v;
    if (v >= mod)
      v -= mod;
    return *this;
  }
  Self &operator-=(const Self r) noexcept {
    if (v < r.v)
      v += mod;
    v -= r.v;
    return *this;
  }
  Self &operator*=(const Self r) noexcept {
    v = reduce(u64(v) * r.v);
    return *this;
  }
  Self &operator/=(const Self r) noexcept {
    u32 a = mod;
    u32 b = reduce(r.v);
    u32 s = 0;
    u32 t = 1;
    while (b != 1) {
      const u32 q = a / b;
      std::swap(a -= q * b, b);
      std::swap(s -= q * t, t);
    }
    if (i32(t) < 0)
      t += mod;
    v = v * t % mod;
    return *this;
  }

  static void set_mod(const u32 m) noexcept {
    assert(m < u32(1) << 31);
    assert(m % 2 == 1);
    mod = m;
    inv = m;
    for (u32 i = 0; i != 4; i += 1)
      inv *= u32(2) - inv * m;
    r2 = -u64(m) % m;
  }
  static u32 get_mod() noexcept { return mod; }
};
typename montgomery_fp::u32 montgomery_fp::mod;
typename montgomery_fp::u32 montgomery_fp::inv;
typename montgomery_fp::u32 montgomery_fp::r2;

#include <utility>

template <class T, class U> constexpr T power(T x, U exp) {
  T ret = static_cast<T>(1);
  while (exp) {
    if (exp % static_cast<U>(2) == static_cast<U>(1))
      ret *= x;
    exp /= static_cast<U>(2);
    x *= x;
  }
  return ::std::move(ret);
}

#include <iostream>
#include <vector>

int main() {
  using mint = montgomery_fp;
  mint::set_mod(1000000007);

  int b, w;
  std::cin >> b >> w;
  int n = b + w;

  std::vector<mint> fact(n);
  fact[0] = 1;
  for (int i = 1; i < n; ++i) {
    fact[i] = fact[i - 1] * i;
  }
  const auto comb = [&fact](int n, int r) {
    return fact[n] / fact[r] / fact[n - r];
  };

  mint p = 0, q = 0;

  for (int i = 1; i <= n; ++i) {
    std::cout << ((mint(1) - p + q) / 2).value() << std::endl;

    if (i >= b) {
      p += comb(i - 1, b - 1) / power(mint(2), i);
    }
    if (i >= w) {
      q += comb(i - 1, w - 1) / power(mint(2), i);
    }
  }

  return 0;
}


Compiler output:
a.cc: In member function 'montgomery_fp::Self& montgomery_fp::operator/=(Self)':
a.cc:56:12: error: 'swap' is not a member of 'std'
   56 |       std::swap(a -= q * b, b);
      |            ^~~~
a.cc:57:12: error: 'swap' is not a member of 'std'
   57 |       std::swap(s -= q * t, t);
      |            ^~~~
a.cc: In function 'int main()':
a.cc:116:42: error: 'using montgomery_fp::Self = class montgomery_fp' {aka 'class montgomery_fp'} has no member named 'value'
  116 |     std::cout << ((mint(1) - p + q) / 2).value() << std::endl;
      |                                          ^~~~~