Once my first test case gets executed , i am getting value error for list, how can i solve this problem?
Code link:- https://drive.google.com/file/d/13Hd6neVCXGprRfXBe5D1W8SV4JDeulDV/view?usp=sharing
Getting value error
Hey @saksham_thukral, you can remove that error by replacing the keywords input by input1 and list by list1 everywhere in your code. You cannot use keywords as variable names in python. So your final code should look something like this :
t= int(input()) # number of test cases
while(t>0):
input1 = list(map(int,input().split()))
n = input1[0]
m = input1[1]
list1 = []
for i in range(n,m+1):
#print(i)
flag = 0
if i==1:
flag=1
else:
for j in range(2,i//2+1):
if(i%j == 0):
flag = 1
if flag == 0:
list1.append(i)
else:
continue
print(*list1)
t = t-1
I hope this helps you resolve this error
Happy Learning
Now i am getting time limit exceed error ie TLE, how can resolve this error in my code?
You need to optimise your code so that it takes less iterations to produce the output ! Try to reduce the number of for loops and iterations your code is taking !
I hope this helps !
Happy coding
how can i reduce the number of iterations , as for now, if i take example of 1-10, and if my i reaches at β4β, then it checks the its factors upto β2β, how can i even further reduce the number of iterations, as in that case on checking for even β4β it will put it into prime numbers as the loop will be running only upto β1β for β4β
Thereβs a technique called Sieve of Eratosthenes. Read about that and you would get your answer
I hope Iβve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.