You are viewing a single comment's thread. Return to all comments →
My solution in python3
def isPrime(n): # This could be the least execution way to find prime numbers if n == 2: return True elif n % 2 == 0: return False for i in range(3, n//2+1, 2): if n % i == 0: return False return True def solve(n): if n == 1: return 0 #Since 1 is not a prime number if isPrime(n): return 1 lSum = sum(list(map(int, str(n)))) rSum = 0 while n % 2 == 0: if isPrime(n): break rSum += 2 n //= 2 i = 3 # if I start checking from 2 then I have to increase 1 for each iteration while not isPrime(n): if not isPrime(i): i += 2 continue if n % i == 0: if i > 9: rSum += sum(list(map(int, str(i)))) else: rSum += i n //= i else: i += 2 rSum += sum(list(map(int, str(n)))) print(lSum) print(rSum) if lSum == rSum: return 1 return 0
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 solution in python3