結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー QCFiumQCFium
提出日時 2021-02-26 23:32:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 468 ms / 2,000 ms
コード長 3,720 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 175,904 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-04-10 14:41:26
合計ジャッジ時間 17,618 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 222 ms
5,632 KB
testcase_13 AC 169 ms
5,376 KB
testcase_14 AC 86 ms
5,376 KB
testcase_15 AC 175 ms
5,376 KB
testcase_16 AC 13 ms
5,376 KB
testcase_17 AC 157 ms
5,376 KB
testcase_18 AC 222 ms
5,760 KB
testcase_19 AC 242 ms
5,760 KB
testcase_20 AC 91 ms
5,376 KB
testcase_21 AC 282 ms
5,632 KB
testcase_22 AC 106 ms
5,376 KB
testcase_23 AC 237 ms
5,504 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 256 ms
5,632 KB
testcase_26 AC 174 ms
5,376 KB
testcase_27 AC 93 ms
5,376 KB
testcase_28 AC 192 ms
5,504 KB
testcase_29 AC 25 ms
5,376 KB
testcase_30 AC 157 ms
5,376 KB
testcase_31 AC 145 ms
5,376 KB
testcase_32 AC 274 ms
5,888 KB
testcase_33 AC 263 ms
5,888 KB
testcase_34 AC 275 ms
5,888 KB
testcase_35 AC 292 ms
5,888 KB
testcase_36 AC 279 ms
5,888 KB
testcase_37 AC 266 ms
5,760 KB
testcase_38 AC 256 ms
6,016 KB
testcase_39 AC 261 ms
5,760 KB
testcase_40 AC 261 ms
6,016 KB
testcase_41 AC 258 ms
5,760 KB
testcase_42 AC 260 ms
5,760 KB
testcase_43 AC 261 ms
5,632 KB
testcase_44 AC 291 ms
5,632 KB
testcase_45 AC 280 ms
5,760 KB
testcase_46 AC 262 ms
5,760 KB
testcase_47 AC 262 ms
5,760 KB
testcase_48 AC 264 ms
5,760 KB
testcase_49 AC 256 ms
5,760 KB
testcase_50 AC 283 ms
5,888 KB
testcase_51 AC 287 ms
5,888 KB
testcase_52 AC 336 ms
5,888 KB
testcase_53 AC 299 ms
5,888 KB
testcase_54 AC 283 ms
5,760 KB
testcase_55 AC 287 ms
5,760 KB
testcase_56 AC 295 ms
5,760 KB
testcase_57 AC 313 ms
5,888 KB
testcase_58 AC 286 ms
5,888 KB
testcase_59 AC 294 ms
5,888 KB
testcase_60 AC 289 ms
6,016 KB
testcase_61 AC 295 ms
5,888 KB
testcase_62 AC 468 ms
5,376 KB
testcase_63 AC 403 ms
9,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

template<int mod>
struct ModInt{
	int x;
	ModInt () : x(0) {}
	ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {}
	ModInt &operator += (const ModInt &p){
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator -= (const ModInt &p) {
		if ((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator *= (const ModInt &p) {
		x = (int64_t) x * p.x % mod;
		return *this;
	}
	ModInt &operator /= (const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt &operator ^= (int64_t p) {
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator - () const { return ModInt(-x); }
	ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
	ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; }
	bool operator == (const ModInt &p) const { return x == p.x; }
	bool operator != (const ModInt &p) const { return x != p.x; }
	explicit operator int() const { return x; }
	ModInt &operator = (const int p) { x = p; return *this;}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			a -= t * b;
			std::swap(a, b);
			u -= t * v;
			std::swap(u, v);
		}
		return ModInt(u);
	}
	friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) {
		return stream << p.x;
	}
	friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) {
		int64_t x;
		stream >> x;
		a = ModInt<mod>(x);
		return stream;
	}
};
typedef ModInt<1000000007> mint;

template<int mod> struct MComb {
	using mint = ModInt<mod>;
	std::vector<mint> fact;
	std::vector<mint> inv;
	MComb (int n) { // O(n + log(mod))
		fact = std::vector<mint>(n + 1, 1);
		for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i);
		inv.resize(n + 1);
		inv[n] = fact[n] ^ (mod - 2);
		for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1);
	}
	mint ncr(int n, int r) {
		return fact[n] * inv[r] * inv[n - r];
	}
	mint npr(int n, int r) {
		return fact[n] * inv[n - r];
	}
	mint nhr(int n, int r) {
		assert(n + r - 1 < (int) fact.size());
		return ncr(n + r - 1, r);
	}
};

int gcd(int a, int b) {
	while (a && b) {
		if (a > b) a %= b;
		else b %= a;
	}
	return a + b;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	struct Info {
		int max = 0;
		int max2 = 0;
		int max_id = -1;
	};
	std::map<int, Info> map;
	for (int i = 0; i < n; i++) {
		auto add = [&] (int j, int cnt) {
			if (map[j].max <= cnt) map[j].max2 = map[j].max, map[j].max = cnt, map[j].max_id = i;
			else if (map[j].max2 < cnt) map[j].max2 = cnt;
		};
		int t = a[i];
		for (int j = 2; j * j <= t; j++) {
			int cnt = 0;
			while (t % j == 0) t /= j, cnt++;
			if (cnt) add(j, cnt);
		}
		if (t > 1) add(t, 1);
	}
	
	mint tmp[n];
	for (auto &i : tmp) i = 1;
	mint all = 1;
	for (auto i : map) {
		// std::cerr << i.first << " " << i.second.max << " " << i.second.max_id << " " << i.second.max2 << std::endl;
		mint r0 = mint(i.first) ^ i.second.max;
		mint alt = mint(i.first) ^ i.second.max2;
		all *= r0;
		tmp[i.second.max_id] /= r0;
		tmp[i.second.max_id] *= alt;
	}
	for (auto &i : tmp) i *= all;
	
	mint prod = 1;
	for (auto i : a) prod *= i;
	
	for (int i = 0; i < n; i++) {
		// std::cerr << tmp[i] << std::endl;
		std::cout << prod / a[i] - tmp[i] << std::endl;
	}
	
	return 0;
}
0