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.
#!/bin/python3importmathimportosimportrandomimportreimportsys## Complete the 'solve' function below.## The function is expected to return an INTEGER.# The function accepts INTEGER n as parameter.#defsum_digits(n):digits=0whilen!=0:digits+=n%10n=n// 10returndigitsdefsum_prime_factors(n):factors=0factor_list=[]whilen%2==0:factors+=2factor_list.append(2)n=n// 2foriinrange(3,int(math.sqrt(n))+1,2):whilen%i==0:factors+=sum_digits(i)factor_list.append(i)n=n// iifn>2:factor_list.append(n)num=sum_digits(n)factors+=numreturnfactorsdefsolve(n):factors=sum_prime_factors(n)digits=sum_digits(n)iffactors==digits:return1else:return0if__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input().strip())result=solve(n)fptr.write(str(result)+'\n')fptr.close()
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 →
My python solution (I'm new to python!):