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.
defprimeFactors(n):# Print the number of two's that divide na=[]whilen%2==0:a.append(2)n=n// 2# n must be odd at this point# so a skip of 2 ( i = i + 2) can be usedforiinrange(3,int(math.sqrt(n))+1,2):# while i divides n , print i and divide nwhilen%i==0:a.append(i)n=n// i# Condition if n is a prime# number greater than 2ifn>2:a.append(n)returnadefsum_of_digits(n):s=0while(n!=0):s+=n%10n=n//10returnsdefsolve(n):# Write your code herea=primeFactors(n)s=0foriinrange(len(a)):ifa[i]<10:s+=a[i]else:s+=sum_of_digits(a[i])s1=sum_of_digits(n)ifs1==s:return1else:return0
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Identify Smith Numbers
You are viewing a single comment's thread. Return to all comments →