# Sherlock and the Beast – HackerRank

I found myself stuck on this problem recently. I must confess, I lost a couple of hours trying to get to figure the logic for this one. Here’s the problem: I’ve written 2 functions to solve this problem. The first one I used for smaller N, say N < 30 and the second one for N > 30. The second function is elegant, and it relies on the mathematical property that if a number N is not divisible by 3, it could either leave a remainder 1 or 2.

If it leaves a remainder 2, then subtracting 5 once would make the number divisible by 3. If it leaves a remainder 1, then subtracting 5 twice would make the number divisible by 3.

We subtract 5 from N iteratively and attempt to divide N into 2 parts, one divisible by 3 and the other divisible by 5. We want the part that is divisible by 3 to be the larger part, so that the associated Decent Number is the largest possible. This explanation might seem obtuse, but if you get pen down on paper, you’ll understand what I mean.

Solution
{"ft_lang_label":"__label__en","ft_lang_prob":0.9427207,"math_prob":0.9256275,"size":967,"snap":"2022-40-2023-06","text_gpt3_token_len":235,"char_repetition_ratio":0.13187954,"word_repetition_ratio":0.043243244,"special_character_ratio":0.24095139,"punctuation_ratio":0.09952607,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99740374,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-06T05:38:55Z\",\"WARC-Record-ID\":\"<urn:uuid:74451d69-81c3-4b87-9dff-72f4cf6c9d9d>\",\"Content-Length\":\"114792\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:494daf9b-97ac-458e-b40a-9317ddc90c02>\",\"WARC-Concurrent-To\":\"<urn:uuid:69198e6c-56c5-4e40-8d5e-0193d051605f>\",\"WARC-IP-Address\":\"192.0.78.24\",\"WARC-Target-URI\":\"https://pythonandr.com/2015/12/12/sherlock-and-the-beast-hackerrank/\",\"WARC-Payload-Digest\":\"sha1:7UCUYDLITFVXYYGC4ER2PP4STSCXCLTF\",\"WARC-Block-Digest\":\"sha1:QC6A7L7ACB2MSIOVJSSNIRF4YS73BJGQ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500304.90_warc_CC-MAIN-20230206051215-20230206081215-00077.warc.gz\"}"}