結果

問題 No.2718 Best Consonance
ユーザー shobonvip
提出日時 2024-04-06 09:55:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,189 ms / 4,000 ms
コード長 1,713 bytes
コンパイル時間 4,688 ms
コンパイル使用メモリ 259,444 KB
最終ジャッジ日時 2025-02-20 22:30:05
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	vector<tuple<ll,ll,ll>> tar;
	rep(i,0,n){
		ll a, b; cin >> a >> b;
		tar.push_back(make_tuple(a * b, a, b));
	}
	
	sort(tar.begin(), tar.end());
	reverse(tar.begin(), tar.end());

	vector<ll> a(n), b(n);
	rep(i,0,n){
		a[i] = get<1>(tar[i]);
		b[i] = get<2>(tar[i]);
	}

	const int mx = 200000;
	vector<ll> see(mx + 1, 1e18);

	vector<vector<int>> d(mx + 1);
	rep(i,1,mx+1){
		for (int j=i; j<=mx; j+=i){
			d[j].push_back(i);
		}
	}

	ll ans = 0;
	rep(i,0,n){
		for (int j: d[a[i]]){
			// A[x] / j = GCD
			if (see[j] < 1e12){
				chmax(ans, (a[i] * b[i]) / (see[j] * a[i]));
			}
			chmin(see[j], a[i] / j);
		}
	}
	cout << ans << '\n';
}

0