結果

問題 No.1253 雀見椪
ユーザー w2w2w2w2
提出日時 2020-10-09 22:47:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 3,091 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 204,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 18:44:42
合計ジャッジ時間 3,538 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 70 ms
4,380 KB
testcase_05 AC 70 ms
4,376 KB
testcase_06 AC 71 ms
4,380 KB
testcase_07 AC 70 ms
4,380 KB
testcase_08 AC 72 ms
4,376 KB
testcase_09 AC 72 ms
4,380 KB
testcase_10 AC 70 ms
4,376 KB
testcase_11 AC 71 ms
4,376 KB
testcase_12 AC 71 ms
4,376 KB
testcase_13 AC 70 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using ld= long double;
using pll= pair<ll, ll>;
using vi= vector<int>;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vpll= vector<pll>;
using vvi= vector<vi>;
using vvl= vector<vl>;
using vvd= vector<vd>;
using vvs= vector<vs>;
using vvb= vector<vb>;
using vvpll= vector<vpll>;
constexpr ll mod= 1e9 + 7;
// constexpr ll mod= 998244353;
#define ALL(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define REPBASE(i, a, b) for(ll(i)= (a); (i) < (b); (i)++)
#define RREPBASE(i, a, b) for(ll(i)= (a); (i) >= (b); (i)--)
#define REPB(i, n) REPBASE(i, 0, n)
#define REPS(i, n) REPBASE(i, 1, n + 1)
#define RREP(i, n) RREPBASE(i, n - 1, 0)
#define RREPS(i, n) RREPBASE(i, n, 1)
#define REP(...) _overload(__VA_ARGS__, REPBASE, REPB)(__VA_ARGS__)
#define EACH(x, c) for(auto &x : c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")
#define SZ(x) ((ll)(x).size())
#define BIT(n) (1LL << (n))
template <class T>
bool chmax(T &a, const T &b) {
    if(a < b) {
        a= b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if(b < a) {
        a= b;
        return 1;
    }
    return 0;
}

/* 最大公約数 */
ll gcdx(ll a, ll b) { return b ? gcdx(b, a % b) : a; }

/* modとる */
inline ll modu(ll a) { return (a % mod + mod) % mod; }

/* 逆元(法mod = 1e9+7) */
ll modinv(ll a) {
    ll b= mod, u= 1, v= 0;
    while(b) {
        ll t= a / b;
        a-= t * b;
        swap(a, b);
        u-= t * v;
        swap(u, v);
    }
    return modu(u);
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res= 1;
    for(a= modu(a); b; a= modu(a * a), b>>= 1) {
        if(b & 1) res= modu(res * a);
    }
    return res;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll T;
    cin >> T;
    REP(idfhim, T) {
        ll N, AG, BG, AC, BC, AP, BP;
        cin >> N >> AG >> BG >> AC >> BC >> AP >> BP;
        ll x= gcdx(AG, BG);
        AG/= x;
        BG/= x;
        x= gcdx(AC, BC);
        AC/= x;
        BC/= x;
        x= gcdx(AP, BP);
        AP/= x;
        BP/= x;
        ll ans= 0;
        ans= modu(modpow(BP, N) * modpow(AG * BC + AC * BG, N)) +
             modu(modpow(BG, N) * modpow(AC * BP + AP * BC, N)) +
             modu(modpow(BC, N) * modpow(AP * BG + AG * BP, N)) -
             2 * modu(modu(modpow(AG, N) * modpow(BC, N)) * modpow(BP, N)) -
             2 * modu(modu(modpow(AC, N) * modpow(BG, N)) * modpow(BP, N)) -
             2 * modu(modu(modpow(AP, N) * modpow(BC, N)) * modpow(BG, N));
        ans= modu(ans);
        ans*= modu(modu(modinv(modpow(BG, N)) * modinv(modpow(BC, N))) *
              modinv(modpow(BP, N)));
        ans= modu(1 - ans);
        cout << ans << "\n";
    }
}
0