Problem p03476 (python)

Fixed submission:
q = int(input())
    
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

ls = [0]

for i in range(1,100000):
    if is_prime(i) and is_prime((i+1)//2):
        ls.append(ls[i-1]+1)
    else:
        ls.append(ls[i-1])
        
for i in range(q):
    l,r = map(int,input().split())
    if l == r:
        if is_prime(l) and is_prime((l+1)//2):
            print(1)
        else:
          print(ls[r]-ls[l-1])  
    else:
        print(ls[r]-ls[l-1])

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

er_list = eratosthenes(100000)
count = []

j = 0
for i in range(er_list[-1]):
    if i == er_list[j]:
        j += 1
        if (i+1)//2 in er_list:
            count.append(1) 
        else:
            count.append(0)
    else:
        count.append(0)
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate

def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

er_list = eratosthenes(100000)
count = []

j = 0
for i in range(er_list[-1]):
    if i == er_list[j]:
        j += 1
        if (i+1)//2 in er_list:
            count.append(1) 
        else:
            count.append(0)
            
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

Buggy submission (verdict: Runtime Error):
import math
def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

ls = eratosthenes(100000)
ls2 = []
count = 0
for i in ls:
    ls2.append(count)
    if (i+1)//2 in ls:
        count += 1
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(ls2[r-1]-ls2[l-1])

Buggy submission (verdict: Runtime Error):
import math
def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

ls = eratosthenes(100000)
ls2 = []
count = 0
for i in ls:
    if (i+1)//2 in ls:
        count += 1
    ls2.append(count)

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(ls2[r]-ls2[l])

Buggy submission (verdict: Runtime Error):
def eratosthenes(n):
    prime_list = []
    num_list=[i for i in range(2, n+1)]
    limit = math.sqrt(n)
    while True:
        if limit <= num_list[0]:
            return prime_list + num_list
        prime_list.append(num_list[0])
        num_list = [e for e in num_list if e % num_list[0] != 0]

ls = eratosthenes(100000)
ls2 = []
count = 0
for i in ls:
    if (i+1)//2 in ls:
        count += 1
    ls2.append(count)

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(ls2[r]-ls2[l])

Buggy submission (verdict: Runtime Error):
def prime_eratosthenes(n):
    prime_list = []
    num_list=[]
    for i in range(2, n+1):
        if i not in num_list:
            prime_list.append(i)
            for j in range(i*i, n+1, i):
                num_list.append(j)
    return prime_list

ls = prime_eratosthenes(10000)
ls2 = [i+1 for i in range(10000)]
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    ans = 0
    for j in range(l-1, r):
        if (ls2[j] in ls) and (ls2[j+1]//2 in ls):
            ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
def prime_eratosthenes(n):
    prime_list = []
    num_list=[]
    for i in range(2, n+1):
        if i not in num_list:
            prime_list.append(i)
            for j in range(i*i, n+1, i):
                num_list.append(j)
    return prime_list

ls = prime_eratosthenes(10000)
ls2 = [i+1 for i in range(10000)]
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    ans = 0
    for j in range(l-1, r):
        if (ls2[j] in ls) and (ls2[j+1]//2 in ls):
            ans += 1
    print(ans)