結果

問題 No.2519 Coins in Array
ユーザー MasKoaTS
提出日時 2023-03-12 16:59:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 662 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 198,192 KB
最終ジャッジ日時 2025-02-11 10:40:55
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other WA * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;

ll gcd(ll a, ll b) {
	while (b != 0) {
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

ll f(ll x, ll y) {
	return (gcd(x, y) == 1) ? (x - 1) * (y - 1) : 0;
}


int main(void) {
	int n;	cin >> n;

	if (n >= 4) {
		cout << 0 << endl;
		return 0;
	}

	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(all(a));

	ll ans = 1000000000000000001ll;
	do {
		ll t = f(a[0], a[1]);
		if (n == 3) {
			t = f(t, a[2]);
		}
		if (ans <= t) {
			continue;
		}
		ans = t;
	} while (next_permutation(all(a)));

	cout << ans << endl;

    return 0;
}
0