#include #include #include

using namespace std;

bool isCompatible(int a, int b) { return a % b != 0; }

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

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

sort(a.begin(), a.end());

int minCompatibility = INT_MAX;
bool hasCompatible = false;

for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
        if (isCompatible(a[i], a[j])) {
            minCompatibility = min(minCompatibility, a[j] % a[i]);
            hasCompatible = true;
        }
    }
}

if (hasCompatible) {
    cout << minCompatibility << endl;
} else {
    cout << "NO" << endl;
}

return 0;
给定一个长度为 n 的整数数组 a1a2a3…an 。我们规定两个整数是相容的当且仅当整数 aiaj 1≤ij≤n 且 ai∤aj ai 不能被 aj 整除即 ajmodai≠0 。我们定义两个相容的整数之间的相容率为 ajmodai 的值。现在请你直接输出数组 a 能够计算得到的最小相容率。如果数组中的元素两两都不是相容的你只需要输出NO。写出c++代码

原文地址: https://www.cveoy.top/t/topic/hQOU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录