From 501093ba1bc4c18db6bb157843d550b0c560831a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 25 Aug 2024 22:59:56 +0800 Subject: [PATCH] =?UTF-8?q?B3941=20[GESP=E6=A0=B7=E9=A2=98=20=E4=BA=94?= =?UTF-8?q?=E7=BA=A7]=20=E5=B0=8F=E6=9D=A8=E7=9A=84=E9=94=BB=E7=82=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.luogu.com.cn/record/174741177 --- Luogu/B3941/B3941.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Luogu/B3941/B3941.cpp diff --git a/Luogu/B3941/B3941.cpp b/Luogu/B3941/B3941.cpp new file mode 100644 index 00000000..cefd3984 --- /dev/null +++ b/Luogu/B3941/B3941.cpp @@ -0,0 +1,39 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 15; + +int n, a[N], ans; + +int gcd(int x, int y) { + if (x == 0) return y; + return gcd(y % x, x); +} + +int lcm(int x, int y) { + return x / gcd(x, y) * y; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 0; i < n; i++) { + cin >> a[i]; + } + + ans = a[0]; + + for (int i = 1; i < n; i++) { + ans = lcm(ans, a[i]); + } + + cout << ans << endl; + + return 0; +}