Sherlock and The Beast

  • + 5 comments

    My solution in python 3:

    def decentNumber(n):
        if n % 3 == 0:
            print('5' * n)    
        elif n % 3 == 1 and n >= 10:
            print( '5'* (n - 10) + '3' * (10))
        elif n % 3 == 2 and n >= 5: 
            print('5' *(n - 5) + '3' * (5))
        else:
            print(-1)    
        return
    

    When you divide by 3, you get remainder 0 or 1 or 2. If it 0, we can have a stirng of all 5's. If the remainder is 1, then if you subtract 10 ( which is 3 * 3 + 1) then the number is divisible by 3 -- however, number should be atleast 10. If remainer is 2, then if you subtract 5 (which is 3 *1 + 2) then the number is divisible by 3 -- however number should be at least 5. Otherwise, print -1.