結果
| 問題 |
No.1253 雀見椪
|
| コンテスト | |
| ユーザー |
keijak
|
| 提出日時 | 2020-10-09 22:56:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 5,965 bytes |
| コンパイル時間 | 2,009 ms |
| コンパイル使用メモリ | 196,748 KB |
| 最終ジャッジ日時 | 2025-01-15 05:34:50 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 RE * 11 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0, REP_N_ = int(n); i < REP_N_; ++i)
#define ALL(x) std::begin(x), std::end(x)
#define SIZE(a) (int)((a).size())
template <class T>
inline bool chmax(T &a, T b) {
return a < b and ((a = std::move(b)), true);
}
template <class T>
inline bool chmin(T &a, T b) {
return a > b and ((a = std::move(b)), true);
}
template <typename T>
using V = std::vector<T>;
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &a) {
for (auto &x : a) is >> x;
return is;
}
template <typename Container>
std::ostream &pprint(const Container &a, std::string_view sep = " ",
std::string_view ends = "\n", std::ostream *os = nullptr) {
if (os == nullptr) os = &std::cout;
auto b = std::begin(a), e = std::end(a);
for (auto it = std::begin(a); it != e; ++it) {
if (it != b) *os << sep;
*os << *it;
}
return *os << ends;
}
template <typename T, typename = void>
struct is_iterable : std::false_type {};
template <typename T>
struct is_iterable<T, std::void_t<decltype(std::begin(std::declval<T>())),
decltype(std::end(std::declval<T>()))>>
: std::true_type {};
template <typename T,
typename = std::enable_if_t<is_iterable<T>::value &&
!std::is_same<T, std::string>::value>>
std::ostream &operator<<(std::ostream &os, const T &a) {
return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &a) {
return os << "(" << a.first << ", " << a.second << ")";
}
#ifdef ENABLE_DEBUG
template <typename T>
void pdebug(const T &value) {
std::cerr << value;
}
template <typename T, typename... Ts>
void pdebug(const T &value, const Ts &... args) {
pdebug(value);
std::cerr << ", ";
pdebug(args...);
}
#define DEBUG(...) \
do { \
std::cerr << " \033[33m (L" << __LINE__ << ") "; \
std::cerr << #__VA_ARGS__ << ":\033[0m "; \
pdebug(__VA_ARGS__); \
std::cerr << std::endl; \
} while (0)
#else
#define pdebug(...)
#define DEBUG(...)
#endif
template <u64 M>
struct ModInt {
constexpr ModInt(long long val = 0) : _v(0) {
if (val < 0) {
long long k = (abs(val) + M - 1) / M;
val += k * M;
}
assert(val >= 0);
_v = val % M;
}
static constexpr int mod() { return M; }
static constexpr u64 umod() { return M; }
inline u64 val() const { return _v; }
ModInt &operator++() {
_v++;
if (_v == umod()) _v = 0;
return *this;
}
ModInt &operator--() {
if (_v == 0) _v = umod();
_v--;
return *this;
}
ModInt operator++(int) {
auto result = *this;
++*this;
return result;
}
ModInt operator--(int) {
auto result = *this;
--*this;
return result;
}
constexpr ModInt operator-() const { return ModInt(-_v); }
constexpr ModInt &operator+=(const ModInt &a) {
if ((_v += a._v) >= M) _v -= M;
return *this;
}
constexpr ModInt &operator-=(const ModInt &a) {
if ((_v += M - a._v) >= M) _v -= M;
return *this;
}
constexpr ModInt &operator*=(const ModInt &a) {
_v = ((unsigned long long)(_v)*a._v) % M;
return *this;
}
constexpr ModInt pow(unsigned long long t) const {
ModInt base = *this;
ModInt res = 1;
while (t) {
if (t & 1) res *= base;
base *= base;
t >>= 1;
}
return res;
}
constexpr ModInt inv() const {
// Inverse by Extended Euclidean algorithm.
// M doesn't need to be prime, but x and M must be coprime.
assert(_v != 0);
// auto [g, x, y] = ext_gcd(_v, M);
// assert(g == 1LL); // The GCD must be 1.
// return x;
// Inverse by Fermat's little theorem.
// M must be prime. It's often faster.
//
return pow(M - 2);
}
constexpr ModInt &operator/=(const ModInt &a) { return *this *= a.inv(); }
friend constexpr ModInt operator+(const ModInt &a, const ModInt &b) {
return ModInt(a) += b;
}
friend constexpr ModInt operator-(const ModInt &a, const ModInt &b) {
return ModInt(a) -= b;
}
friend constexpr ModInt operator*(const ModInt &a, const ModInt &b) {
return ModInt(a) *= b;
}
friend constexpr ModInt operator/(const ModInt &a, const ModInt &b) {
return ModInt(a) /= b;
}
friend constexpr bool operator==(const ModInt &a, const ModInt &b) {
return a._v == b._v;
}
friend constexpr bool operator!=(const ModInt &a, const ModInt &b) {
return a._v != b._v;
}
friend std::istream &operator>>(std::istream &is, ModInt &a) {
return is >> a._v;
}
friend std::ostream &operator<<(std::ostream &os, const ModInt &a) {
return os << a._v;
}
private:
// Extended Euclidean algorithm
// Returns (gcd(a,b), x, y) where `a*x + b*y == gcd(a,b)`.
static std::tuple<int, int, int> ext_gcd(int a, int b) {
int ax = 1, ay = 0, bx = 0, by = 1;
for (;;) {
if (b == 0) break;
auto d = std::div(a, b);
a = b;
b = d.rem;
ax -= bx * d.quot;
std::swap(ax, bx);
ay -= by * d.quot;
std::swap(ay, by);
}
return {a, ax, ay};
}
u64 _v; // raw value
};
const u64 MOD = 1'000'000'007;
using Mint = ModInt<MOD>;
using namespace std;
void solve() {
int n;
Mint ag, bg, ac, bc, ap, bp;
cin >> n >> ag >> bg >> ac >> bc >> ap >> bp;
Mint allg = (ag / bg).pow(n), allc = (ac / bc).pow(n),
allp = (ap / bp).pow(n);
Mint ans = 0;
ans += ((bp - ap) / bp).pow(n);
ans += ((bg - ag) / bg).pow(n);
ans += ((bc - ac) / bc).pow(n);
ans -= 2 * allg + 2 * allc + 2 * allp;
ans = 1 - ans;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
REP(i, T) { solve(); }
}
keijak