Number of Single Divisor Triplets - Problem
You are given a 0-indexed array of positive integers nums. A triplet of three distinct indices (i, j, k) is called a single divisor triplet of nums if nums[i] + nums[j] + nums[k] is divisible by exactly one of nums[i], nums[j], or nums[k].
Return the number of single divisor triplets of nums.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [4,7,9,6]
›
Output:
1
💡 Note:
Only triplet (0,1,3) with values [4,7,6] has sum 17. Check: 17%4≠0, 17%7≠0, 17%6≠0... Actually, let me recalculate: 4+7+6=17, and 17%4=1, 17%7=3, 17%6=5, so no divisors. Let me try (0,1,2): 4+7+9=20, 20%4=0 (✓), 20%7=6 (✗), 20%9=2 (✗). Exactly 1 divisor!
Example 2 — Multiple Valid Triplets
$
Input:
nums = [1,2,3]
›
Output:
0
💡 Note:
Only one triplet (0,1,2): sum = 1+2+3=6. Check divisibility: 6%1=0 (✓), 6%2=0 (✓), 6%3=0 (✓). Has 3 divisors, not exactly 1, so invalid.
Example 3 — Larger Array
$
Input:
nums = [1,1,1,1,1]
›
Output:
0
💡 Note:
All triplets have sum 3, and 3%1=0, so each triplet has 3 divisors (all three 1's divide 3). None have exactly 1 divisor.
Constraints
- 3 ≤ nums.length ≤ 100
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Array of positive integers [4,7,9,6]
2
Check Triplets
For each triplet, calculate sum and test divisibility
3
Count Valid
Return count of triplets with exactly 1 divisor
Key Takeaway
🎯 Key Insight: A triplet is valid when its sum is divisible by exactly one of its three elements
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code