DivisibleByDigits
SRM 375 · 2007-11-10 · by darnley
Problem Statement
Notes
- An integer A starts with an integer B if the string representation of B is a prefix of the string representation of A (both in decimal notation with no leading zeroes).
Constraints
- n will be between 1 and 1000000000, inclusive.
13 Returns: 132
We need a number that starts with 13 and is divisible by 1 (always true) and by 3. The smallest one is 132.
648 Returns: 648
If n is divisible by all its non-zero digits, the answer to the problem is n itself.
566 Returns: 56610
The resulting number must be divisible by 5, so it should end either with 0 or with 5. But a number ending with 5 is odd and can't be divisible by 6. So the last digit of the answer must be 0. In order to make the number divisible by 6, we need to put something before this 0, and the smallest appropriate digit is 1.
308 Returns: 30816
191 Returns: 1917
Submissions are judged against all 88 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DivisibleByDigits with a public method long long getContinuation(int n) · 88 test cases · 2 s / 256 MB per case