1 / 4
Oct 2019

for the problem : https://www.spoj.com/problems/PRIME1/14
title : PRIME1
used python, getting error,need help,

n = int(input())
	
for i in range(n):
	temp = list(map(int, input().split()))

	for i in range(temp[0],temp[1]):

		compare = int(i ** 0.5)
		
		if i % compare != 0 and i % (compare-1) != 0:
			print(i)
	print("\n")
  • created

    Oct '19
  • last reply

    Oct '19
  • 3

    replies

  • 810

    views

  • 2

    users

  • 1

    link

Did you test this with the sample input given in the problem statement? When I did that, it didn’t give any output.

I can’t see where you test the numbers to see whether they’re prime. Did you forget that bit? :wink:

sorry mate, thanks for pointing it out :slight_smile:
below is the code, i later changed ( i forgot to post this one, and posted older one by mistake )

n = int(input())
	
for i in range(n):
	temp = list(map(int, input().split()))

	for i in range(temp[0],temp[1]):

		compare = int(i ** 0.5)
		if compare > 1:
			if i % compare != 0 or i % (compare-1) != 0:
				print(i)
		elif compare <= 1:
			if i % compare != 0 :
				print(i)
			
	print("\n")

Sorry, but I still don’t see a primality test. Try it with the range 10 - 20, and see how many primes it reports.