cpp_library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub toyama1710/cpp_library

:heavy_check_mark: test/aoj/3209.test.cpp

Depends on

Code

#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3209"
#include <cassert>
#include <iostream>

#include "../../math/modint.hpp"

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    constexpr int mod = int(1e9) + 7;
    int n;

    assert((ModInt<mod>(0) - 1).d == mod - 1);
    assert(ModInt<mod>(-1).d == mod - 1);

    while (cin >> n, n > 0) {
        ModInt<mod> a, b, c, d;
        cin >> a >> b >> c >> d;

        ModInt<mod> s1 = (a + c) * (c - a + 1) / 2;
        ModInt<mod> s2 = (b + d) * (1 + d - b) / 2;

        cout << s1 * s2 << '\n';
    }

    return 0;
}
#line 1 "test/aoj/3209.test.cpp"
#define PROBLEM "https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=3209"
#include <cassert>
#include <iostream>

#line 1 "math/modint.hpp"



#line 5 "math/modint.hpp"

template <uint64_t p>
struct ModInt {
    using u64 = unsigned long long;
    using i64 = long long;
    u64 d;

    ModInt(const i64 x = 0) : d((x % i64(p) + p) % p){};
    ModInt(const ModInt &) = default;

    ModInt operator+(ModInt x) const {
        if (d + x.d >= p)
            return ModInt(d + x.d - p);
        else
            return ModInt(d + x.d);
    };

    ModInt operator-(ModInt x) const {
        if (d >= x.d)
            return ModInt(d - x.d);
        else
            return ModInt(d + p - x.d);
    };

    ModInt operator*(ModInt x) const {
        return ModInt(d * x.d);
    }

    ModInt operator/(ModInt x) const {
        return ModInt(*this * x.inv());
    }

    static ModInt pow(ModInt x, uint64_t a) {
        ModInt ret = 1;
        while (a) {
            if (a & 1) ret *= x;
            x *= x;
            a >>= 1;
        }
        return ret;
    };

    ModInt inv() {
        return pow(*this, p - 2);
    };

    ModInt operator+() {
        return *this;
    };

    ModInt operator-() {
        return ModInt(-d);
    };

    ModInt &operator+=(ModInt x) {
        return *this = *this + x;
    };
    ModInt &operator-=(ModInt x) {
        return *this = *this - x;
    };
    ModInt &operator*=(ModInt x) {
        return *this = *this * x;
    };
    ModInt &operator/=(ModInt x) {
        return *this = *this / x;
    };

    ModInt operator+(const i64 x) const {
        return *this + ModInt(x);
    };
    ModInt operator-(const i64 x) const {
        return *this - ModInt(x);
    };
    ModInt operator*(const i64 x) const {
        return *this * ModInt(x);
    };
    ModInt operator/(const i64 x) const {
        return *this / ModInt(x);
    };

    ModInt operator+=(const i64 x) {
        return *this = *this + x;
    };
    ModInt operator-=(const i64 x) {
        return *this = *this - x;
    };
    ModInt operator*=(const i64 x) {
        return *this = *this * x;
    };
    ModInt operator/=(const i64 x) {
        return *this = *this / x;
    };
};

template <uint64_t p>
ModInt<p> operator+(const long long x, const ModInt<p> y) {
    return ModInt<p>(x) + y;
};

template <uint64_t p>
ModInt<p> operator-(const long long x, const ModInt<p> y) {
    return ModInt<p>(x) - y;
};

template <uint64_t p>
ModInt<p> operator*(const long long x, const ModInt<p> y) {
    return ModInt<p>(x) * y;
};

template <uint64_t p>
ModInt<p> operator/(const long long x, const ModInt<p> y) {
    return ModInt<p>(x) / y;
};

template <uint64_t p>
std::ostream &operator<<(std::ostream &stream, const ModInt<p> mi) {
    return stream << mi.d;
};

template <uint64_t p>
std::istream &operator>>(std::istream &stream, ModInt<p> &mi) {
    long long a;
    stream >> a;
    mi = ModInt<p>(a);
    return stream;
};

#line 6 "test/aoj/3209.test.cpp"

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 Itr = a; Itr < b; Itr += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

#define ALL(X) begin(X), end(X)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    constexpr int mod = int(1e9) + 7;
    int n;

    assert((ModInt<mod>(0) - 1).d == mod - 1);
    assert(ModInt<mod>(-1).d == mod - 1);

    while (cin >> n, n > 0) {
        ModInt<mod> a, b, c, d;
        cin >> a >> b >> c >> d;

        ModInt<mod> s1 = (a + c) * (c - a + 1) / 2;
        ModInt<mod> s2 = (b + d) * (1 + d - b) / 2;

        cout << s1 * s2 << '\n';
    }

    return 0;
}
Back to top page