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.
def luckyNumbers(a, b):
lucky_nums=[]
seq=range(a,b+1)
for num in seq:
number=num
sum=0
sum_sqr=0
while num!=0:
remain=num%10
sum+=remain
sum_sqr+=(remain**2)
num=num//10
count1=0
for i in range(1,sum+1):
if(sum%i==0):
count1+=1
count2=0
for j in range(1,sum_sqr+1):
if(sum_sqr%j==0):
count2+=1
if count1==2 and count2==2:
lucky_nums.append(number)
return len(lucky_nums)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lucky Numbers
You are viewing a single comment's thread. Return to all comments →
def luckyNumbers(a, b): lucky_nums=[] seq=range(a,b+1) for num in seq: number=num sum=0 sum_sqr=0 while num!=0: remain=num%10 sum+=remain sum_sqr+=(remain**2) num=num//10