Count Divisible Power Sums
Problem statement
For every exponent triple (x, y, z) with 0 <= x <= maxExponent2, 0 <= y <= maxExponent3, and 0 <= z <= maxExponent5, form 2^x + 3^y + 5^z.
Return the number of exponent triples whose formed number is divisible by divisor.
Different exponent triples are counted separately, even if they produce the same numeric sum.
Implement countDivisiblePowerSums with integer parameters maxExponent2, maxExponent3, maxExponent5, and divisor. Return the number of valid triples as a long.
Function
countDivisiblePowerSums(maxExponent2: int, maxExponent3: int, maxExponent5: int, divisor: int) → longExamples
Example 1
maxExponent2 = 0maxExponent3 = 0maxExponent5 = 0divisor = 3return = 1The only triple is (0, 0, 0), producing 1 + 1 + 1 = 3, which is divisible by 3.
Example 2
maxExponent2 = 1maxExponent3 = 1maxExponent5 = 0divisor = 2return = 2The triples (1, 0, 0) and (1, 1, 0) produce 4 and 6. The other two sums are odd.
Example 3
maxExponent2 = 2maxExponent3 = 2maxExponent5 = 2divisor = 5return = 7Seven of the 27 exponent triples have a power sum congruent to 0 modulo 5.
Constraints
0 <= maxExponent2, maxExponent3, maxExponent5 <= 20001 <= divisor <= 2000- The answer fits in a signed
64-bitinteger.