A relay station's diagnostic firmware inspects the numeric frequency code n currently loaded on a beacon. The firmware calls the tuning resonant precisely when n is evenly divisible by the sum of its own decimal digits. Whenever the tuning is resonant, the diagnostic panel displays that digit sum as a compact calibration offset. Otherwise, the panel displays -1 to flag a misalignment that needs manual recalibration. Given the frequency code, determine what the diagnostic panel displays.
A single line containing one integer n.
Print a single integer: the digit sum of n if n is evenly divisible by that digit sum, otherwise print -1.
Example 1
Input
18
Expected
9
Explanation
The digits of 18 sum to 1+8=9. Since 18 is evenly divisible by 9 (18/9=2), the panel displays the digit sum, 9.
Example 2
Input
23
Expected
-1
Explanation
The digits of 23 sum to 2+3=5. Since 23 is not evenly divisible by 5 (23/5 is not an integer), the panel displays -1 to flag the misalignment.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →