We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sherlock and The Beast
Sherlock and The Beast
Sort by
recency
|
529 Discussions
|
Please Login in order to post a comment
This is my solution. Count 5 (the number of '5' digits) starts completely divisible by 3. Count 3 (the number of '3' digits) is basically the remainder, after substracting count 5 from n. We need to remove multiples of 3 from count5 and add them to count3 until count3 will become divisible by 5. It won't take long. Think about it, any number divided by 5 will have the following remainders 0, 1, 2, 3, 4. If it's 0 you're already there. If it's 1, you need to add 3 three times and consider modulo 5 group with addition: 1 + 3 = 4; 4 + 3 = 2; 2 + 3 = 0; If it's 2, you only need one addition to 3: 2 + 3 = 0 For 3: 3 + 3 = 1; 1 + 3 = 4; 4 + 3 = 2; 2 + 3 = 1 For 4: 4 + 3 = 2; 2 + 3 = 0;
void decentNumber(int n) { int count5 = (n / 3) * 3; int count3 = n - count5;
}
In C#
Here is my c++ solution, you can have the implementation link here : https://youtu.be/R01NQ4Zt2qA