forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.ts
28 lines (28 loc) · 962 Bytes
/
Solution.ts
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
27
28
function singleDivisorTriplet(nums: number[]): number {
const cnt: number[] = Array(101).fill(0);
for (const x of nums) {
++cnt[x];
}
let ans = 0;
const f = (a: number, b: number) => (a % b === 0 ? 1 : 0);
for (let a = 1; a <= 100; ++a) {
for (let b = 1; b <= 100; ++b) {
for (let c = 1; c <= 100; ++c) {
const s = a + b + c;
const t = f(s, a) + f(s, b) + f(s, c);
if (t === 1) {
if (a === b) {
ans += cnt[a] * (cnt[a] - 1) * cnt[c];
} else if (a === c) {
ans += cnt[a] * (cnt[a] - 1) * cnt[b];
} else if (b === c) {
ans += cnt[b] * (cnt[b] - 1) * cnt[a];
} else {
ans += cnt[a] * cnt[b] * cnt[c];
}
}
}
}
}
return ans;
}