Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
37541 lyujixing 组合 C++ 通过 0 MS 248 KB 1439 2024-01-21 15:41:08

Tests(1/1):


#include <bits/stdc++.h> using namespace std; const int N = 25; int arr[N]; int main(){ int n, res = 0; cin >> n; //输入n中规格,存放在arr[0~n-1]中 for(int i = 0; i < n; i++) cin >> arr[i]; sort(arr + 0, arr + n); //n种规格升序 if(arr[0] == 1) { cout << 0 << endl; return 0; } //cout << INT_MAX << endl; 21亿多 int x, y, maxxy = INT_MAX; for(int i = 0; i < n - 1; i++){ for(int j = i + 1; j < n; j++){ if(__gcd(arr[i], arr[j]) == 1){ int num = arr[i] * arr[j] - arr[i] - arr[j]; if(maxxy > num) { maxxy = num; //更新最大值 x = arr[i]; //保存互质数 y = arr[j]; } } } } //如果maxxy != INT_MAX 至少有一组互质数 if(maxxy != INT_MAX){ for(int i = maxxy; i > 0; i--){ bool flag = false; //不能表示 for(int j = 0; j <= i / x; j++){ if((i - j * x) % y == 0){ flag = true; //能表示 break; } } if(flag == false) //不能表示 当前i 还要判断是否是其他规格的倍数 { int flag0 = false; //不是其他数的倍数 for(int j = 0; j < n; j++){ //其他规格 if(i % arr[j] == 0){ //找到了一个是倍数的 flag0 = true; break; } } if(flag0 == false){ res++; //找到了一种规格 } } } cout << res << endl; } else{ cout << -1 << endl; } return 0; }


测评信息: