/* 線分ではなく直線で解いていた、供養 */ //#define NDEBUG #include #include #include #include namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr usize operator"" _z(unsigned long long x) noexcept { return static_cast(x); } class rep { const usize f, l; public: class itr { friend rep; usize i; constexpr itr(const usize x) noexcept : i(x) {} public: void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr rep(const usize first, const usize last) noexcept : f(first), l(last) {} constexpr itr begin() const noexcept { return itr(f); } constexpr itr end() const noexcept { return itr(l); } }; class revrep { const usize f, l; public: class itr { friend revrep; usize i; constexpr itr(usize x) noexcept : i(x) {} public: void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {} constexpr itr begin() const noexcept { return itr(l); } constexpr itr end() const noexcept { return itr(f); } }; template using vec_alias = std::vector; template auto md_vec(const usize n, const T &value) { return std::vector(n, value); } template auto md_vec(const usize n, Args... args) { return std::vector(n, md_vec(args...)); } template constexpr T difference(const T &a, const T &b) { return a < b ? b - a : a - b; } template T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 #include namespace n91 { constexpr std::uint_fast64_t totient(std::uint_fast64_t x) noexcept { using u64 = std::uint_fast64_t; u64 ret = x; for (u64 i = static_cast(2); i * i <= x; ++i) { if (x % i == static_cast(0)) { ret -= ret / i; x /= i; while (x % i == static_cast(0)) { x /= i; } } } if (x != static_cast(1)) { ret -= ret / x; } return ret; } template (1)> class modint { using u64 = std::uint_fast64_t; static_assert(Modulus < static_cast(1) << static_cast(32), "Modulus must be less than 2**32"); u64 a; constexpr modint &negate() noexcept { if (a != static_cast(0)) { a = Modulus - a; } return *this; } public: constexpr modint(const u64 x = static_cast(0)) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+() const noexcept { return modint(*this); } constexpr modint operator-() const noexcept { return modint(*this).negate(); } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = InverseExp; while (exp) { if (exp % static_cast(2) != static_cast(0)) { *this *= rhs; } rhs *= rhs; exp /= static_cast(2); } return *this; } constexpr bool operator==(const modint rhs) const noexcept { return a == rhs.a; } constexpr bool operator!=(const modint rhs) const noexcept { return a != rhs.a; } }; template class modint_constant { public: static constexpr T value = static_cast(v); using value_type = T; }; } // namespace n91 template void multiple_transform(::std::vector &a) { int n = a.size(); ::std::vector sieve(n, true); for (int p = 2; p < n; ++p) { if (sieve[p]) { for (int k = (n - 1) / p; k != 0; --k) { sieve[k * p] = false; a[k] += a[k * p]; } } } for (int i = 0; ++i != n;) { a[i] += a[0]; } } template void inverse_multiple_transform(::std::vector &a) { int n = a.size(); ::std::vector sieve(n, true); for (int i = 0; ++i != n;) { a[i] -= a[0]; } for (int p = 2; p < n; ++p) { if (sieve[p]) { for (int k = 1; k * p < n; ++k) { sieve[k * p] = false; a[k] -= a[k * p]; } } } } #include #include #include #include #include #include namespace n91 { constexpr usize lm(const usize a, const usize b) { if (b < a) { return a - b; } else { return 0_z; } } void main_() { using mint = modint(1000000007)>; const usize h = scan(); const usize w = scan(); const usize n = std::max({h, w, 2_z}); std::vector a012(n), a01(n), a1(n), b012(n), b01(n), b1(n); for (const auto i : rep(1_z, n)) { { const mint t012 = static_cast(lm(h, i)); const mint t0 = static_cast(lm(h, i * 3_z)); usize l = std::max(i * 2_z, h), u = std::min(h + i, i * 3_z); const mint t2 = static_cast(lm(u, l)); a012[i] = t012; a01[i] = t012 - t2; a1[i] = t012 - t0 - t2; } { const mint t012 = static_cast(lm(w, i)); const mint t0 = static_cast(lm(w, i * 3_z)); usize l = std::max(i * 2_z, w), u = std::min(w + i, i * 3_z); const mint t2 = static_cast(lm(u, l)); b012[i] = t012; b01[i] = t012 - t2; b1[i] = t012 - t0 - t2; } } mint ans = static_cast(0); { multiple_transform(a012); multiple_transform(b012); for (const auto i : rep(0_z, n)) { a012[i] *= b012[i]; } inverse_multiple_transform(a012); ans += a012[1_z] * static_cast(2); } { multiple_transform(a01); multiple_transform(b01); for (const auto i : rep(0_z, n)) { a01[i] *= b01[i]; } inverse_multiple_transform(a01); ans -= a01[1_z] * static_cast(2); } { multiple_transform(a1); multiple_transform(b1); for (const auto i : rep(0_z, n)) { a1[i] *= b1[i]; } inverse_multiple_transform(a1); ans += a1[1_z]; } if (h == 2_z) { ans += static_cast(w); } if (w == 2_z) { ans += static_cast(h); } std::cout << ans.value() << std::endl; } } // namespace n91 int main() { n91::main_(); return 0; }