站外TLE求助
查看原帖
站外TLE求助
1339828
Betrayer_of_love楼主2025/2/5 11:38

本人 TLE40ptsTLE ||40pts 代码:

#include <bits/stdc++.h>
#define int long long
using namespace std;
int gcd(int a, int b) {
    while (b != 0) {
        int t = b;
        b = a % b;
        a = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
signed main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        cin >> nums[i];
    }
    set<int> ls;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ls.insert(lcm(nums[i], nums[j]));
        }
    }
    int r = *ls.begin();
    for (int num : ls) {
        r = gcd(r, num);
    }
    cout << r << endl;
    return 0;
}

悬棺

2025/2/5 11:38
加载中...