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.
#******************************## Author: chetan_raikwar ## Date: 18/03/2019 ##******************************## primes up to 500 (sufficient to factorize max int value mostly)primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499]# returns sum of digits of ndefdigitSum(n):ifn==0:return0else:return(n%10)+digitSum(n// 10)#******** main ********#n=int(input())ifn==1:print('0')else:m=nsum1=i=0whilei<len(primes):ifm%primes[i]==0:m//= primes[i]sum1+=primes[i]else:i+=1else:# remaining is primeifm>1:sum1+=m# ultimate digit sum of both sumswhilesum1>9:sum1=digitSum(sum1)sum2=digitSum(n)whilesum2>9:sum2=digitSum(sum2)ifsum1==sum2:print('1')else:print('0')
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 →
I wrote an easy to understand code :)