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.
can anyone let me know how i can optimize it further
!/bin/python3
import math
import os
import random
import re
import sys
#
Complete the 'luckyNumbers' function below.
#
The function is expected to return a LONG_INTEGER.
The function accepts following parameters:
1. LONG_INTEGER a
2. LONG_INTEGER b
#
def luckyNumbers(a, b):
# Write your code here
temp = 0
total = 0
for i in range(a,b+1):
temp = i
totalsum = 0
totalsumsq = 0
while temp != 0:
digit = temp % 10
temp = temp // 10
totalsum = totalsum + digit
totalsumsq = totalsumsq + (digit**2)
def isprime(n):
if n > 1:
for k in range(2,n):
if (n % k) == 0:
return False
return True
else:
return False
isprime(totalsum)
isprime(totalsumsq)
if isprime(totalsum) and isprime(totalsumsq):
total = total + 1
return total
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
first_multiple_input = input().rstrip().split()
a = int(first_multiple_input[0])
b = int(first_multiple_input[1])
result = luckyNumbers(a, b)
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
Lucky Numbers
You are viewing a single comment's thread. Return to all comments →
can anyone let me know how i can optimize it further
!/bin/python3
import math import os import random import re import sys
#
Complete the 'luckyNumbers' function below.
#
The function is expected to return a LONG_INTEGER.
The function accepts following parameters:
1. LONG_INTEGER a
2. LONG_INTEGER b
#
def luckyNumbers(a, b): # Write your code here temp = 0 total = 0
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')