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: Wrong Answer

Solution code:
import sys
f = sys.stdin

def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

sieve = create_prime(50000)


prime = []
for i in range(25001):
    if sieve[i]:
        prime.append(i)

while True:
    n = int(f.readline())
    if n == 0:
        break
    cnt = 0
    temp = n // 2 + 1
    for i in prime:
        if i > temp:
            break
        if sieve[n - i]:
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*- 
import sys,itertools

prime_list = [2,3,5,7,11]

for n in map(int, sys.stdin):
	if n==0: break
	
	prime_sub_list = [p for p in prime_list if p < n]
	
	sum_list = [x+y for x,y in itertools.combinations(prime_sub_list,2)]
	
	print sum_list.count(n)

Submission status: Wrong Answer

Solution code:
import sys,itertools

prim_flg_list=[1]*50000
prim_flg_list[0]=prim_flg_list[1]=0
prim_flg_list[4::2]=[0]*len(prim_flg_list[4::2])
for i in xrange(3,224,2):prim_flg_list[i*i::i]=[0]*len(prim_flg_list[i*i::i])

prime_list = [p for p in xrange(0,50000) if prim_flg_list[p]]

sum_count_list = [0]*100001

iter=itertools.combinations_with_replacement(prime_list,2)
for combi in iter:
	sum_count_list[combi[0]+combi[1]]+=1

for input in map(int, sys.stdin):
	print sum_count_list[input]

Submission status: Wrong Answer

Solution code:
import sys,itertools

input_list = map(int, sys.stdin)
max_input = max(input_list)

prim_flg_list=[1]*max_input
prim_flg_list[0]=prim_flg_list[1]=0
prim_flg_list[4::2]=[0]*len(prim_flg_list[4::2])
for i in range(3,int(max_input**0.5),2):prim_flg_list[i*i::i]=[0]*len(prim_flg_list[i*i::i])

prime_list = [p for p in range(0,max_input) if prim_flg_list[p]]

sum_count_list = [0]*(max_input*2+1)

iter=itertools.combinations_with_replacement(prime_list,2)
for combi in iter:
	sum_count_list[combi[0]+combi[1]]+=1

for input in input_list:
	print sum_count_list[input]

Submission status: Wrong Answer

Solution code:
def primes(n):
  l = [1 for i in range(n+1)]
  l[0] = l[1] = 0
  for i in range(2,int((n)**(1/2))+1):
    if l[i] == 1:
      for j in range(2,n//i+1):
        l[i*j] = 0
  return l

l = primes(50000)
while True:
  n = int(input())
  if n == 0:
    break
  count = 0
  if not(n%2):
    for i in range(3,n//2+1,2):
      if (l[i] and l[n-i]):
        count += 1
  else:
    if l[n-2]:
      count += 1
  print(count)

Submission status: Wrong Answer

Solution code:
import bisect
primes = [0,0] + [1]*49999
for i in range(2, 223):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0

values = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    end = bisect.bisect_left(values, n//2)
    print(sum(1 for i in values[:end+1] if primes[n-i]))

Submission status: Wrong Answer

Solution code:
import bisect
primes = [0,0] + [1]*49999
for i in range(2, 223):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0

values = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    end = bisect.bisect_left(values, n//2)
    print(sum(1 for i in values[:end] if primes[n-i]))

Submission status: Wrong Answer

Solution code:
primes = [0,0] + [1]*49999
for i in range(2, 223):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0

values = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    ans = 0
    for i in values:
        if i > n//2:
            break
        if primes[n-i]:
            ans += 1
    print(ans)

Submission status: Wrong Answer

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 = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    end = bisect.bisect_left(values, n//2)
    print(sum(1 for i in values[:end] if primes[n-i]))

Submission status: Wrong Answer

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 = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    end = bisect.bisect_left(values, n//2)+1
    print(sum(1 for i in values[:end] if primes[n-i]))

Submission status: Wrong Answer

Solution code:
import bisect
primes = [0,0] + [1]*49999
for i in range(2, 225):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0

values = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    end = bisect.bisect_left(values, n//2)+1
    print(sum(1 for i in values[:end] if primes[n-i]))

Submission status: Wrong Answer

Solution code:
isPrime = []

def init():
    for i in range(50000 + 1):
        isPrime.append(True)

def eratos():
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, 50000 + 1):
        for j in range(i * 2, 50000 + 1, i):
            isPrime[j] = False

init()
eratos()
n = int(input())
count = 0
for i in range(2, n // 2 + 1):
    if isPrime[i] & isPrime[n - i]:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
from itertools import combinations_with_replacement

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

def main():
    while True:
        n = int(input())
        if n == 0:
            break
        elif n%2 != 0:
            print('0')
            continue
        prime = []
        for i in range(n):
            if is_prime(i):
                prime.append(i)
        count = 0
        for value in combinations_with_replacement(prime,2):
            if sum(value) == n:
                count += 1
        print(count)

Submission status: Wrong Answer

Solution code:
import math
from itertools import combinations_with_replacement

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

def main():
    while True:
        n = int(input())
        if n == 0:
            break
        prime = []
        for i in range(n):
            if is_prime(i):
                prime.append(i)
        count = 0
        for value in combinations_with_replacement(prime,2):#combinations_with_replacementは重複あり組み合せ
            if sum(value) == n:
                count += 1
        print(count)

Submission status: Wrong Answer

Solution code:
n = 50000
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())
    cnt = 0
    if n == 0:
        break
    elif n%2 == 0:
        for i in range(0, n//2, 2):
            if c[i] == 1 and c[n-i] == 1:
                cnt +=1
    print(cnt*2)

Submission status: Wrong Answer

Solution code:
n = 50000
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())
    cnt = 0
    if n == 0:
        break
    elif n%2 == 0:
        for i in range(0, n//2, 2):
            if c[i] == 1 and c[n-i-2] == 1:
                cnt +=1
    print(cnt*2)

Submission status: Wrong Answer

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

prime = set(is_prime)

while True:
    cnt = 0
    n = int(input())
    if n == 0:
        break
    elif n%2 == 1:
        print(0)
        continue
    for i in prime:
        if i > n//2:
            continue
        if n - i in prime:
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

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

prime_set  = set(is_prime)
prime_set.remove(0)
prime_list = sorted(list(prime_set))

while True:
    cnt = 0
    n = int(input())
    if n == 0:
        break
    elif n%2 == 1:
        print(0)
        continue
    for i in prime_list:
        if i > n//2:
            break
        if n - i in prime_set:
            cnt += 1
    print(cnt)

Submission status: Wrong Answer

Solution code:
import bisect
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 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: Wrong Answer

Solution code:
import bisect,sys
from itertools import *
n=range(50001);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 map(int,sys.stdin):
 if x:print(sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]))

Submission status: Wrong Answer

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 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: Wrong Answer

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
while True:
    n=input()
    if n==0:break
    print c[n]

Submission status: Wrong Answer

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):
    c[i+i]+=1
while True:
    n=input()
    if n==0:break
    print c[n]

Submission status: Wrong Answer

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:
        x=len([e for e in PRIMES if 0<e<=n/2 and SIEVES[(n-e)/2]!=0])
    return x
        
SIEVES=sieve(50000)
PRIMES=filter(None,[2]+SIEVES)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

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: Wrong Answer

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=[2]+filter(None,SIEVES)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

Solution code:
import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
prime = []
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.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 prime.count(m) == 1:
                count += 1
    print count

Submission status: Wrong Answer

Solution code:
import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
pp = []
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)]
        pp.append(i)

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

Submission status: Wrong Answer

Solution code:
import math

r = 50001
sqrt = int(math.sqrt(r))
p = [1]*r
p[0] = 0
pp = []
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)]
        pp.append(i)

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

Submission status: Wrong Answer

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)]
pp = []
for i in range(25000):
    if p[i] == 1:
        pp.append(i)

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

Submission status: Wrong Answer

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)]
pp = []
for i in range(25000):
    if p[i] == 1:
        pp.append(i)

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

Submission status: Wrong Answer

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&1==0:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    elif S[n/2-1]: x=1
    return x

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

Submission status: Wrong Answer

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=1
    elif n&1==0:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    elif S[n/2-1]: x=1
    return x
 
S=sieve(50000)
PRIMES=[2]+filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

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==0:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    elif S[(n-2)/2]: x=1
    return x
 
S=sieve(50000)
PRIMES=[2]+filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

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==0:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    elif S[(n-2)/2]: x=1
    return x
 
S=sieve(50000)
PRIMES=[2]+filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

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=[2]+filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

Submission status: Wrong Answer

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:
        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

Submission status: Wrong Answer

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&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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
    if n % 2 == 1:
        print 0
        continue
    ct = 0
    for v in a:
        if v > n / 2: break
        if b[n - v]:
            ct += 1
    print ct

Submission status: Wrong Answer

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
    if n % 2:
        print 0
        continue
    ret = 0
    for prime in primes_a:
        if prime > n / 2:
            break
        if n - prime in primes_b:
            ret += 1
    print ret

Submission status: Wrong Answer

Solution code:
N = 50000
t = [1]*N
p = []
d = {}
for i in range(3, N + 1, 2):
    if t[i]:
        p.append(i)
        d[i] = 1
        for j in range(3*i, N+1, 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: Wrong Answer

Solution code:
N = 50000
t = [1]*(N + 1)
p = []
d = {}
for i in range(3, N + 1, 2):
    if t[i]:
        p.append(i)
        d[i] = 1
        for j in range(3*i, N+1, 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: Wrong Answer

Solution code:
N = 50000
t = [1]*(N)
p = []
d = {}
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: Time Limit Exceeded

Solution code:
prm=[2,3]
for n in range(5,50000,2):
	for x in prm:
		if n%x==0 and x*x<=n:
			break
	else:
		prm.append(n)
while 1:
	cnt=0
	n=int(input())
	if n==0:
		break
	for i in prm:
		if i>int(n/2):
			break
		elif n-i in prm:
			print(n-i,i)
			cnt+=1
	print(cnt)

Submission status: Time Limit Exceeded

Solution code:
prm=[2,3]
for n in range(5,50000,2):
	for x in prm:
		if n%x==0 and x*x<=n:
			break
	else:
		prm.append(n)
while 1:
	cnt=0
	n=int(input())
	N=int(n/2)
	if n==0:
		break
	for i in prm:
		if i>N:
			break
		elif n-i in prm:
			cnt+=1
	print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import *
import sys

maxnum = 50000
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False
p = [ i for i in xrange(maxnum) if primes[i]]

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    if d % 2 == 1:
        try: p.index(d-2) ;print 1
        except: print 0; continue
    q = [ r for r in p if r < d]
    c = 0
    for j,k in combinations_with_replacement(q,2):
        if j+k==d: c += 1
    print c

Submission status: Time Limit Exceeded

Solution code:
import sys

maxnum = 50000
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    cnt = 0
    for i in xrange(2,int(d/2+1)):
        if primes[i] and primes[d-i]: cnt += 1
    print cnt

Submission status: Time Limit Exceeded

Solution code:
import sys

maxnum = 50001
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    cnt = 0
    for i in xrange(2,int(d/2+1)):
        if primes[i] and primes[d-i]: cnt += 1
    print cnt

Submission status: Time Limit Exceeded

Solution code:
import sys

maxnum = 50001
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    print sum( [ 1 for i in xrange(2,int(d/2+1)) if primes[i] and primes[d-i] ] )

Submission status: Time Limit Exceeded

Solution code:
import sys

maxnum = 50001
primes = [True]*maxnum
primes[0] = primes[1] = False
for i in xrange(maxnum):
    if i >= maxnum**0.5 : break
    if not primes[i]: continue
    for j in xrange(i*2,maxnum,i): primes[j] = False

p = [ i for i in xrange(maxnum) if primes[i] ]

for s in sys.stdin:
    d = int(s)
    if d == 0: break
    q = [ i for i in p if i < d/2+1 ]
    print sum( [ 1 for i in q if primes[d-i] ] )

Submission status: Time Limit Exceeded

Solution code:
import sys
f = sys.stdin


def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

prime = create_prime(50000)

while True:
    n = int(f.readline())
    if n == 0:
        break
    print(sum(1 for i in range(n // 2 + 1) if prime[i] and prime[n - i]))

Submission status: Time Limit Exceeded

Solution code:
import sys
f = sys.stdin

def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

sieve = create_prime(50000)

import time
start = time.clock()
prime = []
for i in range(25001):
    if sieve[i]:
        prime.append(i)

while True:
    n = int(f.readline())
    if n == 0:
        break
    cnt = 0
    for i in prime:
        if i > n // 2 + 1:
            break
        if sieve[n - i]:
            cnt += 1
    print(cnt)
    
print(time.clock()-start)

Submission status: Time Limit Exceeded

Solution code:
import sys
f = sys.stdin

def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

sieve = create_prime(50000)

prime = []
for i in range(25001):
    if sieve[i]:
        prime.append(i)

while True:
    n = int(f.readline())
    if n == 0:
        break
    cnt = 0
    for i in prime:
        if i > n // 2 + 1:
            break
        if sieve[n - i]:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
def pri(n):
    l =[True] * n
    l[0] = l[1] = False
    for i in range(2,n):
        if l[i]:
            for j in range(i*2, n, i):
                l[j] = False
    return l

n=50000
s=pri(n)
l=[i for i in range(n) if s[i]]

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

    if n % 2 == 0:
        for i in range(len(l)):
            for j in range(i, len(l)):
                if l[i] + l[j] == n:
                    sum += 1
                if l[i] > n//2:
                    break
            if l[i] > n//2:
                break
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
def pri(n):
    l =[True] * n
    l[0] = l[1] = False
    for i in range(2,n):
        if l[i]:
            for j in range(i*2, n, i):
                l[j] = False
    return l

n=50000
s=pri(n)
l=[i for i in range(n) if s[i]]

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

    if n % 2 == 0:
        for i in range(len(l)):
            for j in range(i, len(l)):
                if l[i] + l[j] == n:
                    sum += 1
                if l[j] > n:
                    break
            if l[i] > n // 2:
                break
    print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math
def pri(n):
    l =[True] * n
    l[0] = l[1] = False
    for i in range(2,n):
        if l[i]:
            for j in range(i*2, n, i):
                l[j] = False
    return l

n=50000
s=pri(n)
l=[i for i in range(n) if s[i]]

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

    if n % 2 == 0:
        for i in l:
            if i * 2 > n:
                break
            if n - i in l:
                sum += 1


    print(sum)

Submission status: Time Limit Exceeded

Solution code:
import sys

prim_flg_list=[1]*50000
prim_flg_list[0]=prim_flg_list[1]=0
prim_flg_list[4::2]=[0]*len(prim_flg_list[4::2])
for i in xrange(3,224,2):prim_flg_list[i*i::i]=[0]*len(prim_flg_list[i*i::i])

prime_list = [p for p in range(2,50000) if prim_flg_list[p]]

for n in map(int, sys.stdin):
	if n==0: break
	
	prime_sub_list = [p for p in prime_list if p < n]
	
	i = 0
	j = len(prime_sub_list)-1
	count=  0
	while i <= j:
		sum = prime_sub_list[i] + prime_sub_list[j]
		if sum == n:
			count += 1
			i+=1
			j-=1
		elif sum > n:
			j-=1
		else:
			i+=1
	print count

Submission status: Time Limit Exceeded

Solution code:
while True:
	array = []
	result = 0
	n = int(raw_input())
	if n == 0:
		break
	for var1 in range(2, n):
		judge = True
		for var2 in range(2, var1):
			if var1 % var2 == 0:
				judge = False
				break
		if judge:
			array.append(var1)
	
	for var1 in range(0, len(array)):
		for var2 in range(var1, len(array)):
			if array[var1] + array[var2] == n:
				result += 1
				
	print result

Submission status: Time Limit Exceeded

Solution code:
import itertools

def generate_primes(n):
    primes = []
    for i in range(2,n):
        flag = True
        for j in range(2,i):
            if i%j == 0:
                flag = False
        if flag:
            primes.append(i)
    return primes
    
while True:
	n = int(raw_input())
	if n == 0 : break

	primes = generate_primes(n)
		
	prime_list = list(itertools.combinations_with_replacement(primes, 2))
	
	print len(filter(lambda x: sum(x) == n, prime_list))

Submission status: Time Limit Exceeded

Solution code:
import itertools

def generate_primes(n):
    primes = []
    for i in range(1,n,2):
        flag = True
        for j in range(2,i):
            if i%j == 0:
                flag = False
        if flag:
            primes.append(i)
    return primes
    
while True:
	n = int(raw_input())
	if n == 0 : break

	primes = generate_primes(n)
		
	prime_list = list(itertools.combinations_with_replacement(primes, 2))
	
	print len(filter(lambda x: sum(x) == n, prime_list))