From d888fa1788a8e986051ca75db5e3c06e276583ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AC=B8=ED=98=95?= <74577714+alirz-pixel@users.noreply.github.com> Date: Fri, 23 Jan 2026 01:00:17 +0900 Subject: [PATCH] =?UTF-8?q?260122=20:=20[BOJ=2014476]=20=EC=B5=9C=EB=8C=80?= =?UTF-8?q?=EA=B3=B5=EC=95=BD=EC=88=98=20=ED=95=98=EB=82=98=20=EB=B9=BC?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _munhyeong/14476.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 _munhyeong/14476.cpp diff --git a/_munhyeong/14476.cpp b/_munhyeong/14476.cpp new file mode 100644 index 00000000..4e6fbb80 --- /dev/null +++ b/_munhyeong/14476.cpp @@ -0,0 +1,59 @@ +#include +#include + +using namespace std; + +int gcd(int a, int b) { + return b ? gcd(b, a % b) : a; +} + +int main() { + cin.tie(0); + ios::sync_with_stdio(false); + + int N; + cin >> N; + + vector arr(N); + for (auto& e : arr) + cin >> e; + + vector L2R(N); + vector R2L(N); + + L2R[0] = arr[0]; + R2L[N - 1] = arr[N - 1]; + + for (int i = 1; i < N; i++) { + L2R[i] = gcd(L2R[i - 1], arr[i]); + } + + for (int i = N - 2; i >= 0; i--) { + R2L[i] = gcd(R2L[i + 1], arr[i]); + } + + int result = R2L[1]; + int num = arr[0]; + + if (result < L2R[N - 2]) { + num = arr[N - 1]; + result = L2R[N - 2]; + } + + for (int i = 1; i < N - 1; i++) { + int val = gcd(L2R[i - 1], R2L[i + 1]); + if (result < val) { + result = val; + num = arr[i]; + } + } + + if (num % result) { + cout << result << " " << num; + } + else { + cout << -1; + } + + return 0; +}