Skip to content

Instantly share code, notes, and snippets.

@anirudhjayaraman
Created December 12, 2015 01:49
Show Gist options
  • Save anirudhjayaraman/478128372ff1baeb70eb to your computer and use it in GitHub Desktop.
Save anirudhjayaraman/478128372ff1baeb70eb to your computer and use it in GitHub Desktop.
Solution to HackerRank Problem - Sherlock and the Beast
#!/bin/python
import sys
def combinations_sum(n):
k = n/2
combs = []
answers = []
for i in range(0,k+1):
a,b = i, n-i
t = a,b
if a == 0:
if b%3 == 0:
answers.append('5'*b)
elif b%5 == 0:
answers.append('3'*b)
elif a%3 == 0:
if b%5 == 0:
answers.append('5'*a + '3'*b)
elif a%5 == 0:
if b%3 == 0:
answers.append('5'*b + '3'*a)
answer_list = []
if len(answers) == 0:
return -1
else:
for el in answers:
answer_list.append(int(el))
return max(answer_list)
def comb_sum(n):
y = n
while y%3 != 0:
y -= 5
if y%3 == 0 and (n-y)%5 != 0:
y -= 5
return int(y*'5'+(n-y)*'3')
t = int(raw_input().strip())
for a0 in xrange(t):
n = int(raw_input().strip())
if n < 30:
print combinations_sum(n)
else:
print comb_sum(n)
@deepanshusharma007
Copy link

if this code not work, then put

k=n//2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment