Minimum Nonreciprocal Bandits
Problem statement
Every bandit must aim at exactly targetsPerBandit distinct other bandits. A bandit cannot aim at itself, and no pair may aim at each other.
Find the minimum number of participating bandits for which this is possible. For this exercise, assume the reported two-target puzzle is generalized to the supplied positive target count, with an exact integer result. You only return the minimum count; you do not output a targeting arrangement.
Complete minimumBandits(targetsPerBandit).
Function
minimumBandits(targetsPerBandit: int) → intExamples
Example 1
targetsPerBandit = 2return = 5The reported two-target case needs five bandits. Arrange them in a cycle and let each aim at the next two; no pair aims at each other.
Example 2
targetsPerBandit = 1return = 3Three bandits can form one directed cycle. Two bandits would have to aim at each other.
Example 3
targetsPerBandit = 3return = 7In a cycle of seven, each bandit aims at the next three. The reverse offsets are four through six, so no reciprocal pair occurs.
Constraints
- For this exercise, assume
1 <= targetsPerBandit <= 1000000000. - All required targets are distinct and different from the aiming bandit.
- The returned minimum fits a signed 32-bit integer.