-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2344.cpp
More file actions
26 lines (23 loc) · 762 Bytes
/
2344.cpp
File metadata and controls
26 lines (23 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
public:
int minOperations(vector<int>& nums, vector<int>& numsDivide) {
int numsDivideSize = numsDivide.size();
int gcdVal = numsDivide[0];
for (int i = 1; i < numsDivideSize; ++i) {
gcdVal = (int)__gcd(gcdVal, numsDivide[i]);
}
int count = 0;
// find the smallest multi of gcdVal
int smallest = INT_MAX;
for (int i = 0; i < nums.size(); ++i) {
if (gcdVal % nums[i] == 0) {
smallest = min(smallest, nums[i]);
}
}
if (smallest == INT_MAX) return -1;
for (int i = 0; i < nums.size(); ++i) {
if (nums[i] < smallest) count++;
}
return count;
}
};