Problem:


ゴールドバッハの予想

4 以上の偶数は 2 つの素数の和で表すことができるということが知られています。これはゴールドバッハ予想といい、コンピュータの計算によりかなり大きな数まで正しいことが確かめられています。例えば、10 は、7 + 3、5 + 5 の 2 通りの素数の和で表すことができます。

整数 n を入力し、n を 2 つの素数の和で表す組み合わせ数が何通りあるかを出力するプログラムを作成してください。ただし、n は 4 以上、50,000 以下とします。また、入力される n は偶数であるとはかぎりません。

Input

複数のデータセットが与えられます。各データセットに n が１行に与えられます。n が 0 のとき入力の最後とします。データセットの数は 10,000 を超えません。

Output

各データセットに対して、n を 2 つの素数の和で表す組み合わせ数を１行に出力して下さい。

Sample Input

10
11
0

Output for the Sample Input

2
0



Sample input:
10
11
0


Sample output:
2
0

Submission status: Accepted

Solution code:
#!/usr/bin/env python:
# -*- coding: utf-8 -*-

import sys

def make_prime_list(lim):
    lst = [True for i in xrange(lim + 1)]

    num = 2
    while num ** 2 <= lim:
        for i in xrange(num * 2, lim + 1, num):
            lst[i] = False
        num += 1
        while not lst[num]:
            num += 1
    return [i for i in xrange(2, lim + 1) if lst[i]]

def binary_search(n, prime_list):
    rLim = len(prime_list) - 1
    lLim = 0
    while lLim < rLim:
        middle = (rLim + lLim) / 2
        if prime_list[middle] == n:
            return middle
        elif prime_list[middle] < n:
            lLim = middle + 1
        else:
            rLim = middle - 1
    while prime_list[rLim] < n and rLim < len(prime_list) - 1:
        rLim += 1
    return rLim    

def solve():
    prime_list = make_prime_list(50000)
    while True:
        n = input()
        if n > 0:
            if n % 2 == 0:
                count = 0
                index = 0
                rev_index = binary_search(n, prime_list)
                while index <= rev_index:
                    while prime_list[index] + prime_list[rev_index] > n:
                        rev_index -= 1
                    if index <= rev_index and prime_list[index] + prime_list[rev_index] == n:
                        count += 1
                    index += 1
                print count
            else:
                if n - 2 in prime_list:
                    print 1
                else:
                    print 0
        else:
            sys.exit()

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import itertools
N=50000+1
p=[True]*N
p[0],p[1]=False,False
for i in xrange(2,int(N**0.5)+1):
    if p[i]==True:
        for j in xrange(i**2,N,i):
            p[j]=False
plist=[i for i in xrange(N) if p[i]]
c=[0]*N*2
for i,j in itertools.combinations(plist,2):
    c[i+j]+=1
for i in xrange(N):
    if p[i]:c[i+i]+=1
while True:
    n=input()
    if n==0:break
    print c[n]

Submission status: Accepted

Solution code:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(m):
    L = [True for _ in xrange(m + 1)]
    L[0] = L[1] = False

    for i in xrange(2, m + 1):
        if L[i]:
            for j in xrange(i + i, m + 1, i):
                L[j] = False
            if m < i * i:
                break
    return L

FLAGS = enum_prime(50000)
PRIMES = [i for i, isprime in enumerate(FLAGS) if isprime]

for line in stdin:
    if line.startswith('0'):
        break
    n = int(line)
    n2 = n // 2
    cnt = 0
    if n % 2 == 0:
        for p in PRIMES:
            if p > n2:
                break
            if FLAGS[n - p]:
                cnt += 1
    elif FLAGS[n - 2]:
        cnt = 1
    print(cnt)

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4 : x=0
    elif n==4: x=1
    elif n%2==1:
        if SIEVES[(n-2)/2]!=0:
            x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a:break
            if SIEVES[(n-e)/2]!=0:
                x+=1
    return x

SIEVES=sieve(50000)
PRIMES=filter(None,SIEVES)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]:
            x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]:
                x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

prime = []
for i in range(len(p)):
    if p[i] == 1:
        prime.append(i+1)

while True:
    n = int(raw_input())
    if n == 0:
        break
    count = 0
    for i in prime:
        if i > n/2:
            break
        m = n - i
        if p[m-1] == 1:
                count += 1
    print count

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    i=0
    while i<h:
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
        i+=1
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2:
        if S[(n-2)/2]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[n/2-1]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
from itertools import *

def sieve(n):
    a = range(n)
    a[:2] = None, None
    for i in range(2, n):
        if i ** 2 >= n: break
        if not a[i]: continue
        for i in range(i ** 2, n, i):
            a[i] = None
    return a

b = sieve(50000)
a = [v for v in b if v]
while True:
    n = int(raw_input())
    if n == 0: break
    ct = 0
    for v in a:
        if v > n / 2: break
        if b[n - v]:
            ct += 1
    print ct

Submission status: Accepted

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes_a = sieve(25000)
primes_b = set(sieve(50000))
while 1:
    n = input()
    if n == 0:
        break
    ret = 0
    for prime in primes_a:
        if prime > n / 2:
            break
        if n - prime in primes_b:
            ret += 1
    print ret

Submission status: Accepted

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes = sieve(50000)
ret = [0] * 100001
for i in xrange(len(primes)):
    for j in xrange(i, len(primes)):
        tmp = primes[i] + primes[j]
        if tmp > 50000:
            break
        ret[tmp] += 1
while 1:
    n = input()
    if n == 0:
        break
    print ret[n]

Submission status: Accepted

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes = sieve(50000)
ret = [0] * 50001
for i in xrange(len(primes)):
    for j in xrange(i, len(primes)):
        tmp = primes[i] + primes[j]
        if tmp > 50000:
            break
        ret[tmp] += 1
while 1:
    n = int(input())
    if n == 0:
        break
    print ret[n]

Submission status: Accepted

Solution code:
def sieve(n):
    primes = [True] * n
    primes[0] = primes[1] = False
    for i in xrange(2, int(n ** 0.5) + 1):
        if primes[i]:
            for j in xrange(i * i, n, i):
                primes[j] = False
    return [i for i in xrange(n) if primes[i]]

primes = sieve(50000)
ret = [0] * 50001
for i in xrange(len(primes)):
    for j in xrange(i, len(primes)):
        tmp = primes[i] + primes[j]
        if tmp > 50000:
            break
        ret[tmp] += 1
while 1:
    n = int(raw_input())
    if n == 0:
        break
    print ret[n]

Submission status: Accepted

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x
 
S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Accepted

Solution code:
N = 50000
t = [1]*(N)
p = [2]
d = {2:1}
for i in range(3, N, 2):
    if t[i]:
        p.append(i)
        d[i] = 1
        for j in range(3*i, N, 2*i): t[j] = 0

while True:
    n = int(input())
    if n == 0: break

    count = 0
    if n % 2:
        if n - 2 in p: count += 1
    else:
        for p1 in p:
            if 2*p1 > n: break
            if n - p1 in d:
                count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys

N = 50000
t = [1]*(N)
p = [2]
d = {2:1}
for i in range(3, N, 2):
    if t[i]:
        p.append(i)
        d[i] = 1
        for j in range(3*i, N, 2*i): t[j] = 0

while True:
    n = int(sys.stdin.readline())
    if n == 0: break

    count = 0
    if n % 2:
        if n - 2 in p: count += 1
    else:
        for p1 in p:
            if 2*p1 > n: break
            if n - p1 in d:
                count += 1
    print(count)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write

L = 50000
sq = int(L**.5)
p = [1]*(L+1)
p[0] = p[1] = 0
pn = []
for x in range(sq+1):
    if not p[x]:
        continue
    for y in range(x*x, L+1, x):
        p[y] = 0
    pn.append(x)
for x in range(sq+1, L+1):
    if not p[x]:
        continue
    pn.append(x)
pp = [0]*(L+1)
L0 = len(pn)
for i in range(L0):
    x = pn[i]
    for j in range(i+1):
        z = x + pn[j]
        if z > L:
            break
        pp[z] += 1

def solve():
    N = int(readline())
    if N == 0:
        return False
    write("%d\n" % pp[N])
    return True
while solve():
    ...

Submission status: Accepted

Solution code:
#4から50000までの素数を見つけ出す
MAX=50001
SQRT=233

num=[True for i in range(MAX)]
def prime(num):
    num[0]=num[1]=False
    for i in range(4,MAX,2):
        num[i]=False
    for i in range(2,SQRT+1):
        if num[i]==True:
            for j in range(i*i,MAX,i):
                num[j]=False

prime(num)

prime_num=[i for i in range(MAX) if num[i]==True]
#print(len(num))
def count(num,n):
    #数える処理
    total=0
    #足していく
    for i in prime_num:
        if i>(n/2):
            break
        if num[n-i]==True:
            #print(i)
            total+=1
    return total
    

while True:
    n=int(input())
    if n==0:
        break
    print(count(num,n))

Submission status: Accepted

Solution code:
import math

num = 50000
L = [True] * (num+1)
L[0] = L[1] = False
sqrt = int(num**0.5) +1
for i in range(2, sqrt):
    if L[i] == False:
        continue
    for j in range(i*2,num+1,i):
        L[j] = False

p = [x for x in range(num+1) if L[x] ]

#pset = set(p)

while True:
    num = int(input())
    if num == 0:
        break

    half = num // 2
    c = 0
    for i in p:
        if i > half:
            break
        j = num - i
        if L[j]:
            c += 1
    print(c)

Submission status: Accepted

Solution code:
p = [1] * (50000 + 1)
p[0], p[1] = 0, 0
for i in range(2, int(50000 ** 0.5) + 1):
    if not p[i]:
        continue
    for j in range(2 * i, 50000 + 1, i):
        p[j] = 0

p_num = [i for i in range(50000 + 1) if p[i] == 1]


while 1:
    n = int(input())
    if (n == 0):
        break
    cnt = 0
    for i in p_num:
        if n // 2 < i:
            break
        if p[n - i]:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
LIM = 50001
 
# prepare primes
 
is_prime = [True for _ in range(LIM)]
 
is_prime[0] = is_prime[1] = False
 
# sieve of eratosthenes
for x in range(LIM//2 + 1):
    if is_prime[x]:
        for y in range(x*x, LIM, x):
            is_prime[y] = False
 
primes = [x for x in range(LIM) if is_prime[x]]
 
# END `prepare primes`
 
count_arr = [0 for x in range(LIM)]
 
len_primes = len(primes)
 
for x in range(len_primes):
    p = primes[x]
    for y in range(x, len_primes):
        q = primes[y]
        if p+q >= LIM:
            break
        count_arr[p+q] += 1
 
while True:
    n = int(input())
    if n == 0:
        break
    print(count_arr[n])

Submission status: Accepted

Solution code:
p = [True for i in range(50000)]
p[0] = 0
for i in range(2,int(50000**(1/2)+1)):
    if p[i-1]:
        for j in range(i**2,50000,i):
            p[j-1] = False

prime = [i+1 for i in range(50000) if p[i]]

while(1):
    n = int(input())
    if not n:
        break
    count = 0
    half = n//2
    for i in prime:
        if i > half:
            break
        if p[n - i - 1]:
            count += 1
    print(count)

Submission status: Runtime Error

Solution code:
def make_ps(n):
    tbl = [False, True, False, False, False, True] * (n // 6 + 1)
    for i in range(1, 4):
        tbl[i] = not tbl[i]
    p, stp, sqrt = 5, 2, n ** 0.5
    while p < sqrt:
        for i in range(p ** 2, n, 2 * p):
            tbl[i] = False
        while True:
            p += stp
            stp = 6 - stp
            if tbl[p]:
                break
    return [i for i in range(n) if tbl[i]]
ps = make_ps(n)
while True:
    n = int(input())
    if not n:
        break
    res = 0
    if n % 2:
        if n - 2 in ps:
            res += 1
    else:
        res = 0
        for p in ps:
            if p > n / 2:
                break
            if n - p in ps:
                res += 1
    print(res)

Submission status: Runtime Error

Solution code:
N = 50001
lst = [True] * N
lst[0] = False
lst[1] = False
for i in range(2, int(N ** 0.5) + 1):
    if lst[i]:
        for j in range(i * i, N, i):
            lst[j] = False

primes = [i for i in range(1, N) if lst[i]]

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break
    elif n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for prime0 in primes:
            prime1 = n - prime0
            if prime0 <= prime1 and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

Submission status: Runtime Error

Solution code:
import bisect
primes = [0, 0] + [1] * 49999
for i in range(2, 224):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0
values = [i for i, k in enumerate(primes) if k]
while True:
    n = int(input())
    if n == 0:
        break
    I = bisect.bisect(values, n//2)
    print([i for i, v in enumerate(values[:I]) if primes[n-v]][-1] + 1)

Submission status: Runtime Error

Solution code:
n = 50001
c = [1 for i in range(n)]
c[0] = 0
i = 2
while i**2 <= n:
    j = i*2
    while j <= n:
        c[j - 1] = 0
        j += i
    i += 1

while True:
    n = int(input())
    if n == 0:
        break
    elif n%2 == 1:
        print(0)
        continue
    cnt = 0
    for i in range(n/2):
        if c[i] == 1 and c[n-i] == 1:
            cnt +=1
    print(cnt)

Submission status: Runtime Error

Solution code:
n = 30000
is_prime = [True for i in range(n)]
is_prime[0] = is_prime[1] = False
i = 2
while i**2 <= n:
    j = i*2
    while j < n:
        is_prime[j] = False
        j += i
    i += 1

cnt_pair = [0 for i in range(n)]
for i in range(n):
    if is_prime[i]:
        for j in range(i, n):
           if i + j >= n:
               break
           if is_prime[j]:
               cnt_pair[i + j] += 1

while True:
    n = int(input())
    if n == 0:
        break
    print(cnt_pair[n])

Submission status: Runtime Error

Solution code:
import bisect
from itertools import *
n=range(49994);a=list(n)
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):
 x=int(x)
 y=bisect.bisect(p,x//2)
 if x%2:print(sum(1 for c in p[1:y]if 2+c==x))
 elif x-4:print(sum(1 for c in p[1:y]if a[x-c]))
 else:print(1)

Submission status: Runtime Error

Solution code:
import bisect
from itertools import *
n=range(49994);a=list(n)
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):
 x=int(x)
 y=bisect.bisect(p,x//2)
 if x%2:print(sum(1 for c in p[1:x]if 2+c==x))
 elif x-4:print(sum(1 for c in p[1:y]if a[x-c]))
 else:print(1)

Submission status: Runtime Error

Solution code:
import bisect
from itertools import *
n=range(49994);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):
 x=int(x)
 if x%2:print(sum(2+c==x for c in p[:bisect.bisect(p,x)]))
 elif x-4:print(sum(1 for c in p[:bisect.bisect(p,x//2)]if a[x-c]))
 else:print(1)

Submission status: Runtime Error

Solution code:
import bisect
from itertools import *
n=range(49994);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):
 x=int(x)
 if x%2:print(sum(2+c==x for c in p[:bisect.bisect(p,x)-1]))
 elif x-4:print(sum(1 for c in p[:bisect.bisect(p,x//2)]if a[x-c]))
 else:print(1)

Submission status: Runtime Error

Solution code:
import bisect,sys
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in map(int,sys.stdin):
 if x:print(len(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]))

Submission status: Runtime Error

Solution code:
MAX = 50001

is_prime = [True for _ in range(MAX)]
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX ** (1 / 2)) + 1):
  if is_prime[i]:
    for j in range(i ** 2, MAX, i):
      is_prime[j] = False

primes = [i for i in range(MAX) if is_prime[i]]

def main():
  while True:
    n = int(input())
    if not n:
      break
    
    ans = 0
    for i in primes_less_than_n:
      if is_prime[n - i]:
        ans += 1
  
    print(ans)

main()

Submission status: Runtime Error

Solution code:
n=5*10**4
p=[True]*n
p[0],p[1]=False,False
for i in xrange(2,int(n**0.5)+1):
    if p[i]==True:
        for j in xrange(i**2,n,i):
            p[j]=False
while True:
    n=input()
    if n==0:break
    for i in xrange(n/2+1):
        if p[i] and p[n-i]:c+=1
    print c

Submission status: Runtime Error

Solution code:
N=5000+1
p=[True]*N
p[0],p[1]=False,False
for i in xrange(2,int(N**0.5)+1):
    if p[i]==True:
        for j in xrange(i**2,N,i):
            p[j]=False
c=[0]*N
for i in xrange(N):
    for j in xrange(i/2+1):
        if p[j] and p[i-j]:c[i]+=1
while True:
    n=input()
    if n==0:break
    print c[n]

Submission status: Runtime Error

Solution code:
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0] * ((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n%2==1:
        if SIEVES[(n-2)/2]!=0: x=1
    else:
        for e in PRIMES:
            if e>n/2: break
            if SIEVES[(n-e)/2]!=0]:x+=1
    return x
        
SIEVES=sieve(50000)
PRIMES=filter(None,SIEVES)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Runtime Error

Solution code:
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]:
            x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]:
                x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Runtime Error

Solution code:
r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]

while True:
    n = int(raw_input())
    if n == 0:
        break
    count = 0
    for i in range(n/2):
        if p[i] == 1:
            m = n - (i+1)
            if p[m-1] == 1:
                count += 1
    print count

Submission status: Runtime Error

Solution code:
def enum_prime(m):
    L = [True for _ in range(m + 1)]
    L[0] = L[1] = False

    for i in range(2, m + 1):
        if L[i]:
            for j in range(i + i, m + 1, i):
                L[j] = False
            if m < i * i:
                break
    return L

FLAGS = enum_prime(50000)
PRIMES = [i for i, isprime in enumerate(FLAGS) if isprime]

while True:
    n = int(input())
    n2 = n // 2
    cnt = 0
    if n % 2 == 0:
        for p in PRIMES:
            if p > n2:
                break
            if FLAGS[n - p]:
                cnt += 1
    elif FLAGS[n - 2]:
        cnt = 1
    print(cnt)