Please provide the solution in python language

please provide the solution in python language

Hey @Deep50, we are not allowed to give you the solutions directly. You should first try the questions on your own and if there are any doubts or problems you are facing, then you can ask me anytime.

Hope this helps.
Happy Learning :slight_smile:

i mean , i unlock the solution but the solution given in another language

I am just saying that you give it a try on your own. If you are stuck anywhere then ask me directly the doubt. Giving you the complete solution would not help you in learning the process of thinking the approach.
Please give it a try once !

Happy coding :slight_smile:

yes your right but i am stuck to taking input i’ll try my best but not able to take input then i unlock the solution but the solution in another language (not in python)

i=int(input()) for x in range(i): l=[int(number) for number in input().split()] start = l[0] end = l[1] for val in range(start, end + 1): if val > 1: for n in range(2, val//2 + 2): if (val % n) == 0: break else: if n == val//2 + 1: print(val)

Okay great ! Now let me help you out regarding the input. You have to take the input something like this :

i=int(input())
for x in range(i): 
    l=[int(number) for number in (input().split())] 
    start = l[0] 
    end = l[1]
    
    Logic of rest of the code

So I believe you are taking the input correctly . Is there any error you are getting ?
Also please provide the online IDE link of your code. It is difficult to check the code without indentation.

Hope this helps.
Happy Learning :slight_smile:

when i take single line input the it works otherwise not

You have to take the input like this :

2
1 10
3 5

Here 1 10 is the first test case and 3 5 is the second test case !

What issue you are facing now ?

please check i send to you

TLE problem is shown

Did you try running your code ?..It does not produce the correct output. Try implementing the correct code , then it won’t give you this error.

I Hope you find your mistake :slight_smile:
If you are not able to then try running your code and see the output.

please check this code i chage few code and again this is shown same error

Now your code logic is correct and is producing exactly the correct results. But the time complexity of your code is O(n^2). Try to reduce the complexity on your own first. Hint : I don’t think you really need to check from 2 to i//2+1 for every number ? If the number is even , then directly skip that number as it will never be prime. Check only for odd numbers. Likewise you can try reducing the complexity.
You would get to learn the logic once you try on your own !

Hope this help!
Happy coding :slight_smile:

now i am skip with 2 step in the loop but the error is same

@Deep50, I said you don’t need to check for even numbers. Like if the test case is :

1
1 10

Then you don’t need to check for 4,6,8 as these even numbers will never be prime. So you have chosen j i.e. the divisor to be odd . But you have to take the i ,i.e. the dividend, to be odd and not j. Anyways since it’s been a long time you trying to solve this question, let me provide you the solution now :

def checkPrime(num):
    if num==0 or num==1 :
        return False
    elif num==2 :
        return True
    elif num%2==0 :
        return False
    else :
        i=2
        while(i*i<=num):
            if(num % i==0):
                return False
            i=i+1
        return True
        
            
    

T = int(input())
while(T>0):
    l = [int(i) for i in (input().split())]
    x = l[0]
    y = l[1]
    
    for i in range(x,y+1):
        if (checkPrime(i)):
            print(i,end=" ")
            
    print()
    
    T -= 1

I hope you got to learn a lot of things while finding the approach to solve this problem. I hope this resolves your doubt.
All the best and Happy coding :slight_smile:

thanks sir you tech in a well so i will remember it for life thank you sir