From 49ddbf3558dc49bff9f46a6354078679a7231209 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 23 May 2022 11:50:15 +0800 Subject: [PATCH] CF1154G Minimum Possible LCM https://www.luogu.com.cn/record/76270218 --- Luogu/CF1154G/CF1154G.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Luogu/CF1154G/CF1154G.cpp diff --git a/Luogu/CF1154G/CF1154G.cpp b/Luogu/CF1154G/CF1154G.cpp new file mode 100644 index 00000000..0a37d3c2 --- /dev/null +++ b/Luogu/CF1154G/CF1154G.cpp @@ -0,0 +1,55 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e7 + 5; + +int n, pos[N], x, y; +long long ans = std::numeric_limits::max(); + +int main() { + std::ios::sync_with_stdio(false); + + cin >> n; + + for (int i = 1, t; i <= n; i++) { + cin >> t; + + if (pos[t] && t < ans) { + ans = t; + x = pos[t]; + y = i; + } + + pos[t] = i; + } + + for (int i = 1; i <= 1e7; i++) { + int t = 0; + + for (int j = i; j <= 1e7; j += i) { + if (!pos[j]) continue; + + if (!t) { + t = j; + } else { + long long lcm = 1ll * t * j / i; + + if (lcm < ans) { + ans = lcm; + x = pos[t]; + y = pos[j]; + } + + break; + } + } + } + + cout << std::min(x, y) << ' ' << std::max(x, y) << endl; + + return 0; +}