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.
defbest_divisor(n):sums=[]divisors=[]foriinrange(1,n+1):ifn%i==0:divisors.append(i)sums.append(sum_digits(i))# index = sums.index(max(sums))# print(divisors[index])returndivisors[sums.index(max(sums))]defsum_digits(n):sum=0fordinstr(n):sum+=int(d)returnsum
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Best Divisor
You are viewing a single comment's thread. Return to all comments →
**Python 3: **