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: Time Limit Exceeded

Solution code:
def pri(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i=i+1
    return 1

l=[]
for i in range(2,50100):
    if pri(i):
        l.append(i)
s=len(l)
while 1:
    n=int(raw_input())
    ans=set([])
    if n==0:
        break
    for i in range(s):
        for j in range(i,s):
            if l[i]+l[j]==n:
                ans.add((min(l[i],l[j]),max(l[i],l[j])))
            elif i+j>n:
                break
    print len(ans)

Submission status: Time Limit Exceeded

Solution code:
def pri(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i=i+1
    return 1

l=[]
for i in range(2,50100):
    if pri(i):
        l.append(i)
s=5143
while 1:
    n=int(raw_input())
    ans=set([])
    if n==0:
        break
    for i in range(s):
        for j in range(i,s):
            if l[i]+l[j]==n:
                ans.add((min(l[i],l[j]),max(l[i],l[j])))
            elif l[i]+l[j]>n:
                break
    print len(ans)

Submission status: Time Limit Exceeded

Solution code:
def pri(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i=i+1
    return 1

l=[]
for i in range(2,50100):
    if pri(i):
        l.append(i)
s=5143
while 1:
    n=int(raw_input())
    ans=set([])
    if n==0:
        break
    for i in range(s):
        if l[i]>n:
            break
        for j in range(i,s):
            if l[i]+l[j]==n:
                ans.add((min(l[i],l[j]),max(l[i],l[j])))
            elif l[i]+l[j]>n:
                break
    print len(ans)

Submission status: Time Limit Exceeded

Solution code:
def pri(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i=i+1
    return 1

l=[]
for i in range(2,50100):
    if pri(i):
        l.append(i)
s=5143
while 1:
    n=int(raw_input())
    ans=0
    if n==0:
        break
    for i in range(s):
        if l[i]>n:
            break
        elif n-l[i] in l:
            ans+=1
    print ans

Submission status: Time Limit Exceeded

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

import array


def primes_by_eratosthenes(limit, typecode="Q"):

    search_list = array.array(typecode, range(2, limit + 1))
    primes = array.array(typecode)
    while True:
        p = search_list.pop(0)
        primes.append(p)
        if p * p > limit:
            break
        else:
            search_list = array.array(typecode, filter(
                lambda x: x % p != 0, search_list))
    primes.extend(search_list)
    return primes


if __name__ == "__main__":
    primes = primes_by_eratosthenes(50000, "I")
    while True:
        n = int(input())
        if n == 0:
            break
        elif n % 2 == 1:
            if n - 2 in primes:
                print(1)
            else:
                print(0)
        else:
            result = 0
            for p in primes:
                if 2 * p > n:
                    break
                elif n - p in primes:
                    result += 1
            print(result)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt, floor

p = [2]
for i in range(3, 50000, 2):
    for j in range(3, floor(sqrt(i)) + 1, 2):
        if not i % j:
            break
    else:
        p.append(i)

while True:
    n = int(input())
    if not n:
        break
    n2 = n // 2
    cnt = 0
    for i in p:
        if n2 < i:
            break
        if n - i in p:
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt, floor
from bisect import bisect_left


def search(x):
    global p, lp
    i = bisect_left(p, x)
    return i != lp and p[i] == x


p = [2]
for i in range(3, 50000, 2):
    for j in range(3, floor(sqrt(i)) + 1, 2):
        if not i % j:
            break
    else:
        p.append(i)
lp = len(p)

while True:
    n = int(input())
    if not n:
        break
    if n & 1:
        print(int(search(n - 2)))
        continue
    n2 = n // 2
    cnt = 0
    for i in p:
        if n2 < i:
            break
        if search(n - i):
            cnt += 1
    print(cnt)

Submission status: Time Limit Exceeded

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(50000)
while True:
    n = int(input())
    if not n:
        break
    if n % 2:
        print(1 if n - 2 in ps else 0)
    else:
        res = 0
        for p in ps:
            if p > n / 2:
                break
            if n - p in ps:
                res += 1
        print(res)

Submission status: Time Limit Exceeded

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]]
while True:
    n = int(input())
    ps = make_ps(n)
    if not n:
        break
    if n % 2:
        print(1 if n - 2 in ps else 0)
    else:
        res = 0
        for p in ps:
            if p > n / 2:
                break
            if n - p in ps:
                res += 1
        print(res)

Submission status: Time Limit Exceeded

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]]
while True:
    n = int(input())
    ps = make_ps(n)
    if not n:
        break
    if n % 2:
        print(1 if n - 2 in ps else 0)
    else:
        res = 0
        for p in ps:
            if p > n / 2:
                break
            if n - p in ps:
                res += 1
    print(res)

Submission status: Time Limit Exceeded

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(50000)
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: Time Limit Exceeded

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(50000)
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 2 * p > n:
                break
            if n - p in ps:
                res += 1
    print(res)

Submission status: Time Limit Exceeded

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
  for i in range(1,n//2+1):
    if (l[i] and l[n-i]):
      count += 1
  print(count)

Submission status: Time Limit Exceeded

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
  l2 = [n for n in range(len(l)) if l[n]]
  return l2

l = primes(50000)

while True:
  n = int(input())
  if n == 0:
    break
  count = 0
  for i in range(1,n//2+1):
    if (i in l) and ((n-i) in l):
      count += 1
  print(count)

Submission status: Time Limit Exceeded

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
  l2 = [n for n in range(len(l)) if l[n]]
  return l2

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

Submission status: Time Limit Exceeded

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
  for i in range(2,n//2+1):
    if (l[i] and l[n-i]):
      count += 1
  print(count)

Submission status: Time Limit Exceeded

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


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

Submission status: Time Limit Exceeded

Solution code:
n=50000
p=[1]*(n+1)
p[0],p[1]=0,0
for i in range(2,int(n**0.5)+1):
    if p[i]:        
        for j in range(i*i,n+1,i):
            p[j]=0
#p=[i for i in range(n+1) if p[i]==1]
while 1:
    n=int(input())
    if n==0:break
    c=0
    for i in range(2,n//2+1):
        if(p[i],p[n-i])==(1,1):c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
p=[1]*50001
for i in range(2,int(50000**0.5)+1):
    if p[i]:
        for j in range(i*i,50000,i):p[j]=0
while 1:
    n=int(input())
    if n==0:break
    print(sum(1 for i in range(2,n//2+1) if p[i] and p[n-i]))

Submission status: Time Limit Exceeded

Solution code:
p=[]
for i in range(2,50000):
    for j in range(2,int(i**0.5)+1):
        if not i%j:break
    else:p+=[i]
while 1:
    n=int(input())
    if n==0:break
    print(sum(1 for i in range(2,n//2+1) if i in p and n-i in p))

Submission status: Time Limit Exceeded

Solution code:
p=[]
for i in range(2,50000):
    for j in range(2,int(i**0.5)+1):
        if not i%j:break
    else:p+=[i]
while 1:
    n=int(input())
    if n==0:break
    if n&1:print(int(n-2 in p))
    else:print(sum(1 for i in range(2,n//2+1) if i in p and n-i in p))

Submission status: Time Limit Exceeded

Solution code:
p=[]
for i in range(2,50000):
    for j in range(2,int(i**0.5)+1):
        if not i%j:break
    else:p+=[i]
while 1:
    n=int(input())
    if n==0:break
    c=0
    if n&1:print(int(n-2 in p));continue
    else:
        for x in p:
            if x>n//2:break
            if n-x in p:c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
p=[2]
for i in range(3,50000,2):
    for j in range(2,int(i**0.5)+1):
        if not i%j:break
    else:p+=[i]
while 1:
    n=int(input())
    if n==0:break
    c=0
    if n&1:c=int(n-2 in p)
    else:
        for x in p:
            if x>n//2:break
            if n-x in p:c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
p=[i for i in range(50000)]
for i in range(2,int(50000**0.5)+1):
    if p[i]:
        for j in range(i*i,50000,i):p[j]=0
p=sorted(set(p))[2:]
while 1:
    n=int(input())
    if n==0:break
    c=0
    if n&1:c=int(n-2 in p)
    else:
        for x in p:
            if x>n//2:break
            if n-x in p:c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
N=50000
p=[i for i in range(N)]
for i in range(2,int(N**0.5)+1):
    if p[i]:
        for j in range(i*i,N,i):p[j]=0
p=sorted(set(p))[2:]
while 1:
    n=int(input())
    if n==0:break
    c=0
    if n&1:c=int(n-2 in p)
    else:
        for x in p:
            if x>n//2:break
            if n-x in p:c+=1
    print(c)

Submission status: Time Limit Exceeded

Solution code:
p=[1]*50001
for i in range(2,int(50000**0.5)+1):
    if p[i]:
        for j in range(i*i,50000,i):p[j]=0
while 1:
    n=int(input())
    if n==0:break
    print(sum(1 for i in range(2,n//2) if p[i] and p[n-i]))

Submission status: Time Limit Exceeded

Solution code:
def sieve(n):
    is_prime = [True] * (n + 1)
    for i in range(2,n + 1):
        if is_prime [i] == False:
            continue
        for j in range(i * 2,n + 1,i):
            is_prime [j] = False
    return {i for i in range(2,n + 1) if is_prime [i]}

prime = sieve(100000)

while True:
    N = int(input())
    if N == 0:
        break
    ans = 0
    for i in range(2,N // 2 + 1):
        if i in prime and (N - i) in prime:
            ans += 1
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def sieve(n):
    is_prime = [True] * (n + 1)
    for i in range(2,n + 1):
        if is_prime [i] == False:
            continue
        for j in range(i * 2,n + 1,i):
            is_prime [j] = False
    return {i for i in range(2,n + 1) if is_prime [i]}

prime = sieve(100000)
dic = {}

while True:
    N = int(input())
    if N == 0:
        break
    if N in dic:
        print(dic [N])
        continue
    ans = 0
    for i in range(2,N // 2 + 1):
        if i in prime and (N - i) in prime:
            ans += 1
    print(ans)
    if not N in dic:
        dic [N] = ans

Submission status: Time Limit Exceeded

Solution code:
def sieve(n):
    is_prime = [True] * (n + 1)
    for i in range(2,n + 1):
        if is_prime [i] == False:
            continue
        for j in range(i * 2,n + 1,i):
            is_prime [j] = False
    return [i for i in range(2,n + 1) if is_prime [i]]

prime = sieve(50000)
dic = {}

for i in prime:
    for j in prime:
        if i < j:
            continue
        if i + j in dic:
            dic [i + j] += 1
        else:
            dic [i + j] = 1

while True:
    N = int(input())
    if N == 0:
        break
    if N in dic:
        print(dic [N])
    else:
        print(0)

Submission status: Time Limit Exceeded

Solution code:
def sieve(n):
    is_prime = [True] * (n + 1)
    for i in range(2,n + 1):
        if is_prime [i] == False:
            continue
        for j in range(i * 2,n + 1,i):
            is_prime [j] = False
    return [i for i in range(2,n + 1) if is_prime [i]]

prime = sieve(50000)
dic = {}

for i in prime:
    for j in prime:
        if i < j or i + j > 50000:
            continue
        if i + j in dic:
            dic [i + j] += 1
        else:
            dic [i + j] = 1

while True:
    N = int(input())
    if N == 0:
        break
    if N in dic:
        print(dic [N])
    else:
        print(0)

Submission status: Time Limit Exceeded

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
while True:
    n = int(input())
    if n == 0:
        break
    ans = 0
    mid = n // 2
    if primes[mid] and n%2 == 0:
        ans += 1
    left = [k for k, b in enumerate(primes[:mid]) if b]
    right = [k+mid+1 for k, b in enumerate(primes[mid+1:n]) if b]
    for i in right:
        for j in left:
            if i+j == n:
                ans += 1
                break
            if i+j > n:
                break
    print(ans)

Submission status: Time Limit Exceeded

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

primes = [k for k, b in enumerate(primes) if b]
while True:
    n = int(input())
    if n == 0:
        break
    ans = 0
    mid = n // 2
    if mid in primes and n%2==0:
        ans += 1
    l, r = bisect.bisect_left(primes, mid), bisect.bisect_left(primes, n)
    left = [v for v in primes[:l]]
    right = [v for v in primes[l:r]]
    for i in right:
        for j in left:
            if i+j == n:
                ans += 1
                break
            if i+j > n:
                break
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

memo = {}

def is_prime(n):
    if n in memo:
        return memo[n]

    if n==2 or n==3:
        return True
    if n%2==0 or n<2:
        return False
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            memo[n] = False
            return False
    memo[n] = True
    return True

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if is_prime(n - 2):
            print(1)
        else:
            print(0)
    else:
        counter = 0
        for i in range(1, n, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and is_prime(prime0) and is_prime(prime1):
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

memo = {}

def is_prime(n):
    if n in memo:
        return memo[n]

    if n==2 or n==3:
        return True
    if n%2==0 or n<2:
        return False
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            memo[n] = False
            return False
    memo[n] = True
    return True

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if is_prime(n - 2):
            print(1)
        else:
            print(0)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and is_prime(prime0) and is_prime(prime1):
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

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(2, N):
            index = i * j
            if index < N:
                lst[i * j] = False
print('len', len(lst))

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and lst[prime0] and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

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(2, N // i + 1):
            index = i * j
            if index < N:
                lst[i * j] = False

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and lst[prime0] and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

N = 50001
lst = [True] * N
lst[0] = False
lst[1] = False
for i in range(4, N // 2 + 1, 2):
    lst[i] = False
for i in range(3, int(N ** 0.5) + 1, 2):
    if lst[i]:
        for j in range(2, N // i + 1):
            index = i * j
            if index < N:
                lst[i * j] = False

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    if n % 2 == 1:
        if lst[n - 2]:
            print(1)
        else:
            print(0)
    elif n == 4:
        print(1)
    else:
        counter = 0
        for i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and lst[prime0] and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

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(2 * i, N, i):
            lst[j] = False

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 i in range(1, n // 2 + 1, 2):
            prime0 = i
            prime1 = n - i
            if prime0 <= prime1 and lst[prime0] and lst[prime1]:
                #print(prime0, prime1)
                counter += 1
        print(counter)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import sys
import os

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: Time Limit Exceeded

Solution code:
import sys

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: Time Limit Exceeded

Solution code:
#??¨????????????????????????
prime = [1 for i in range(50000)]
prime[0]=2
prime[1]=0
l = []
for i in range(2,50000):
    if prime[i]==1:
        prime[0]=i

        for j in range(i+1,50000):
            if j%prime[0] == 0:
                prime[j] = 0

for i in range(1,50000):
    if prime[i] == 1:
        l.append(i)

while 1:
    count = 0
    num = int(input())
    if num == 0:
        break
    for i in range(len(l)):
        for j in range(i,len(l)):
            if num == (l[i] + l[j]):
                count +=1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#??¨????????????????????????
prime = [1 for i in range(50000)]
prime[0]=2
prime[1]=0
l = []
for i in range(2,int(50000**(1/2))):
    if prime[i]==1:
        prime[0]=i
        for j in range(i+1,50000):
            if j%prime[0] == 0:
                prime[j] = 0

for i in range(1,50000):
    if prime[i] == 1:
        l.append(i)

while 1:
    count = 0
    num = int(input())
    if num == 0:
        break
    for i in range(len(l)):
        for j in range(i,len(l)):
            if num == (l[i] + l[j]):
                count += 1
    print(count)

Submission status: Time Limit Exceeded

Solution code:
#??¨????????????????????????
prime = [1 for i in range(50000)]
prime[0]=2
prime[1]=0
l = []
for i in range(2,int(50000**(1/2))):
    if prime[i] == 1:
        for j in range(2,50000):
            if i*j >= 50000:
                break
            else:
                prime[i*j] = 0

for i in range(1,50000):
    if prime[i] == 1:
        l.append(i)

while 1:
    count = 0
    num = int(input())
    if num == 0:
        break
    for i in range(len(l)):
        if l[i] >= num:
            break
        else:
            for j in range(i,len(l)):
                if num < (l[i] + l[j]):
                    break
                else:
                    if num == (l[i] + l[j]):
                        count += 1
    print(count)

Submission status: Time Limit Exceeded

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()
while True:
    n = int(input())
    if n == 0:
        break
    
    count = 0
    for i in range(2, n // 2 + 1):
        if isPrime[i] & isPrime[n - i]:
            count += 1

    print(count)

Submission status: Time Limit Exceeded

Solution code:
isPrime = []
prime = []

import math

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

def eratos():
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(math.sqrt(50000)) + 1):
        if (isPrime[i]):
            for j in range(i * 2, 50000 + 1, i):
                isPrime[j] = False
    
    for i in range(2, 50001):
        if isPrime[i]:
            prime.append(i)

init()
eratos()

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

    count = 0
    if n % 2:
        if isPrime[n - 2]:
            count += 1
    else:
        if n == 4:
            count += 1
        else:
            for i in prime:
                if i > (n // 2):
                    break
                if (n - i) in prime:
                    count += 1
    
    print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt, ceil, pow


# https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py
class SieveOfAtkin:
    def __init__(self, limit):
        self.limit = limit
        self.primes = []
        self.sieve = [False] * (self.limit + 1)

    def flip(self, prime):
        try:
            self.sieve[prime] = True if self.sieve[prime] == False else False
        except KeyError:
            pass

    def invalidate(self, prime):
        try:
            if self.sieve[prime] == True: self.sieve[prime] = False
        except KeyError:
            pass

    def isPrime(self, prime):
        try:
            return self.sieve[prime]
        except KeyError:
            return False

    def getPrimes(self):
        testingLimit = int(ceil(sqrt(self.limit)))

        for i in range(testingLimit):
            for j in range(testingLimit):
                # n = 4*i^2 + j^2
                n = 4 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and (n % 12 == 1 or n % 12 == 5):
                    self.flip(n)

                # n = 3*i^2 + j^2
                n = 3 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and n % 12 == 7:
                    self.flip(n)

                # n = 3*i^2 - j^2
                n = 3 * int(pow(i, 2)) - int(pow(j, 2))
                if n <= self.limit and i > j and n % 12 == 11:
                    self.flip(n)

        for i in range(5, testingLimit):
            if self.isPrime(i):
                k = int(pow(i, 2))
                for j in range(k, self.limit, k):
                    self.invalidate(j)

        self.primes = [2, 3] + [x for x in range(len(self.sieve)) if self.isPrime(x) and x >= 5]
        return self.primes


def solve(num, primes):
    result = 0
    sub_primes = [x for x in primes if x < num]
    for x in sub_primes:
        if (num-x) in sub_primes:
            result += 1
            if (num-x)*2 == num:
                result += 1
    return result//2




if __name__ == '__main__':
    A = SieveOfAtkin(50000)
    A.getPrimes()
    while True:
        num = int(input())
        if num == 0:
            break

        # ????????¨???????????¨???
        result = solve(num, A.primes)
        print(result)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt, ceil, pow


# https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py
class SieveOfAtkin:
    def __init__(self, limit):
        self.limit = limit
        self.primes = []
        self.sieve = [False] * (self.limit + 1)

    def flip(self, prime):
        try:
            self.sieve[prime] = True if self.sieve[prime] == False else False
        except KeyError:
            pass

    def invalidate(self, prime):
        try:
            if self.sieve[prime] == True: self.sieve[prime] = False
        except KeyError:
            pass

    def isPrime(self, prime):
        try:
            return self.sieve[prime]
        except KeyError:
            return False

    def getPrimes(self):
        testingLimit = int(ceil(sqrt(self.limit)))

        for i in range(testingLimit):
            for j in range(testingLimit):
                # n = 4*i^2 + j^2
                n = 4 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and (n % 12 == 1 or n % 12 == 5):
                    self.flip(n)

                # n = 3*i^2 + j^2
                n = 3 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and n % 12 == 7:
                    self.flip(n)

                # n = 3*i^2 - j^2
                n = 3 * int(pow(i, 2)) - int(pow(j, 2))
                if n <= self.limit and i > j and n % 12 == 11:
                    self.flip(n)

        for i in range(5, testingLimit):
            if self.isPrime(i):
                k = int(pow(i, 2))
                for j in range(k, self.limit, k):
                    self.invalidate(j)

        self.primes = [2, 3] + [x for x in range(len(self.sieve)) if self.isPrime(x) and x >= 5]
        return self.primes


def solve(num, primes):
    result = 0
    sub_primes = set(x for x in primes if x < num)
    for x in sub_primes:
        if (num-x) in sub_primes:
            result += 1
            if (num-x)*2 == num:
                result += 1
    return result//2




if __name__ == '__main__':
    A = SieveOfAtkin(50000)
    A.getPrimes()
    while True:
        num = int(input())
        if num == 0:
            break

        # ????????¨???????????¨???
        result = solve(num, A.primes)
        print(result)