結果

問題 No.1253 雀見椪
ユーザー maimaicorgimaimaicorgi
提出日時 2022-09-21 11:12:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 2,893 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 138,944 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-23 19:53:54
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <ios>
#include <iomanip>
#include <queue>
#include <numeric>
#include <map>
#include <set>
#include <sstream>
#include <bitset>
#include <climits>
#include <stack>
#include <regex>
#include <functional>
#include <random>
#ifdef _WIN64
#  include <atcoder/all>
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountl __popcnt64
#endif

using namespace std;

#define ll long long
#define rep(i, init, n) for(ll i = init; i < (ll)n; i++)
#define rrep(i, init, n) for(ll i = init; i >= (ll)n; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) (ll)(x.size())
#define Out(x) cout << x << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define Ans cout << ans << endl
#define PI 3.14159265358979
#define MOD 1000000007

const int inf32 = INT_MAX / 2;
const ll inf64 = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// -------------------------------------------------------------------------------------------------

struct mint
{
	ll x;

	mint(ll val = 0) { x = (val % MOD + MOD) % MOD; }

	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint& other) { x += other.x; if (x >= MOD) x -= MOD; return *this; }
	mint& operator-=(const mint& other) { x -= other.x; if (x < 0) x += MOD; return *this; }
	mint& operator*=(const mint& other) { (x *= other.x) %= MOD; return *this; }
	mint& operator/=(const mint& other) { *this *= other.pow(MOD - 2); return *this; }
	mint operator+(const mint& other) const { return mint(*this) += other; }
	mint operator-(const mint& other) const { return mint(*this) -= other; }
	mint operator*(const mint& other) const { return mint(*this) *= other; }
	mint operator/(const mint& other) const { return mint(*this) /= other; }

	mint pow(ll i) const
	{
		mint ret = 1;
		for (mint tmp = x; i; tmp *= tmp, i >>= 1) if (i & 1) ret *= tmp;
		return ret;
	}

	friend ostream& operator<<(ostream& os, const mint& m) { os << m.x; return os; }
};
ll mpow(ll x, ll y)
{
	if (y == 0) return 1;

	x %= MOD;
	if (x == 0) return 0;

	if (y % 2 == 0) return mpow(x * x % MOD, y / 2) % MOD;
	else return x * mpow(x, y - 1) % MOD;
}

int main()
{
	int t; cin >> t;

	vector<mint> ans;

	while (t--)
	{
		ll n, a1, b1, a2, b2, a3, b3; cin >> n >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;

		mint g = (mint)a1 / b1;
		mint c = (mint)a2 / b2;
		mint p = (mint)a3 / b3;

		auto calc = [&](mint a, mint b) { return (mint)mpow((a + b).x, n) - mpow(a.x, n) - mpow(b.x, n); };

		ans.push_back((mint)1 - calc(g, c) - calc(c, p) - calc(p, g));
	}

	for (mint a : ans) Out(a);

	return 0;
}
0