please help me for this problem
cook your dish here
for i in range(int(input())):
m,n = map(int,input().split())
prime =
for i in range(m,n+1):
prime.append(i)
if prime[0]==1:
prime[0] = 0
if(len(prime)>3):
p = 2
while(pp<=n):
if p!=0:
for i in range((p2)-1,n+1,p):
prime[i]=0
p = p+1
for i in prime:
if i !=0:
print(i)
else:
for num in prime:
if num>2:
for i in range(2,num):
if num%i==0:
break
else:
print(num)
what is the problem in my code
Hello, Ak
I read this is your first time posting something, so let me give you a warm welcome.
As for your question, take into consideration that indentation is one of the most important elements in Python, so I’m sorry to say that it will be almost impossible to guess what is going on your code.
Please try using the “</>” botton or using this symbol:
```
# Your code goes here
```
can you provide me solution of this problem(prime generator)
Sure.
Just consider that these 1000~ ranked problems usually are meant to push you into researching how your programing language works, or building your own customized functions for usual problems, like ceiling a number, know if a number is prime or the sum of the first N natural integers.
This problem can be solved in two ways:
- The shared way for all languages:
Build your very efficient “is_prime” function, like this:
# A customized function (VERY useful)
def is_prime(n):
if n < 2:
return False
elif n == 2 or n == 3:
return True
elif n % 2 == 0 or n % 3 == 0:
return False
for i in range(5, int(n**0.5)+1, 6):
if n % i == 0 or n % (i+2) == 0:
return False
return True
# Problem itself
for T in range(int(input()):
M, N = map(int, input().split())
for i in range(M,N+1):
if is_prime(i):
print(i)
print()
- The second way (in Python) was using the sympy library (extremely useful) in two ways. Spot the difference, it’s useful.
from sympy import isprime
for T in range(int(input())):
M, N = map(int, input().split())
for i in range(M,N+1):
if isprime(i):
print(i)
print()
Or
from sympy import primerange
for T in range(int(input())):
M, N = map(int, input().split())
primes = primerange(M,N+1)
for P in primes:
print(P)
print()
Although asking in forums is very valid, remember to never forget to make your online research first. Researching is your most powerfull tool.