title: Wrong Answer to SPOJ PRIME1 in Python
body: <p>I've tried to compare my result to Wolfram Alpha's result by counting primes found.</p>
  
  <p>It seems works well, without error.</p>
  
  <p>But when I submit this solution to SPOJ, it shows the error message "wrong answer".</p>
  
  <p>I also tried to change the final print's end= to '' (blank string), but still got "wrong answer".</p>
  
  <p>Not sure if is there something wrong with my sieve algorithm, or output error.</p>
  
  <p>**edit: link of problem <a href="http://www.spoj.pl/problems/PRIME1/" rel="nofollow">http://www.spoj.pl/problems/PRIME1/</a></p>
  
  <p>Here is my PRIME1 source code, hope someone can point out my fault. Thanks a lot.</p>
  
  <p>And hope someone can teach me how to write a test to programs like this, I'm still learning, don't know how to do automated tests to programs, but want to learn.</p>
  
  <pre><code>    def getPrimeInRange(minNum, maxNum):
          #just a variation with skipping step of the  Sieve of E's
          processingRange = list(range(minNum, maxNum+1))
          #prefix, due to 1 is not a prime
          if minNum == 1:
              processingRange[0] = 0
          sqrtOfMaxNum = int(maxNum ** 0.5) + 1
          primesUnderSqrt = list(range(sqrtOfMaxNum))
          #prefix, due to 1 is not a prime
          primesUnderSqrt[1] = 0
  
          #my strategy is flip all numbers that is not a prime to zero, which equals to False.
          #for Sieve of E's, all the primes under sqrt of max num are the only needed numbers to sieve primes out.
          #so here is a smaller Sieve of E's for numbers under sqrt
          for n in primesUnderSqrt:
              if n: #which equals to "if n != 0"
                  nowIndex = n + n
                  while True:
                      try:
                          primesUnderSqrt[nowIndex] = 0
                          nowIndex += n
                      except IndexError:
                          break
  
          #full aspect sieve
          for n in primesUnderSqrt:
              if n:
                  #for easier flip processing, I need the offset number for the flipping.
                  nMultipleMostCloseToMin = n * (minNum // n)
                  if nMultipleMostCloseToMin == minNum:
                      nowIndex = 0
                  elif sqrtOfMaxNum &lt;= minNum:
                      nowIndex = nMultipleMostCloseToMin + n - minNum
                  elif sqrtOfMaxNum &gt; minNum:
                      nowIndex = nMultipleMostCloseToMin + n - minNum + n
  
                  #happy flippin'
                  while True:
                      try:
                          processingRange[nowIndex] = 0
                          nowIndex += n
                      except IndexError:
                          break
  
          return processingRange
  
      def main():
          todoTimes = int(input())
          todoNums = list(range(todoTimes))
          stringOutput = ''
          for i in range(todoTimes):
              todoNums[i] = input().split()
              todoNums[i][0] = int(todoNums[i][0])
              todoNums[i][1] = int(todoNums[i][1])
          for [minNum, maxNum] in todoNums:
              #countedNum = 0 #for algo debugging
              for n in getPrimeInRange(minNum, maxNum):
                  if n:
                      stringOutput += str(n)
                      #countedNum += 1 #for algo debugging
                      stringOutput += '\n'
              stringOutput += '\n'
              #stringOutput += str(countedNum) #for algo debugging
          stringOutput = stringOutput.rstrip('\n')
          print(stringOutput)
  
  
      ifMainSucceed = main()
  </code></pre>