1. Problem
2. My Solution
import sys
m,n = map(int,sys.stdin.readline().strip().split())
for num in range(m,n+1):
if num >1:
flag = True
for i in range(2,num):
if num % i == 0:
flag = False
break
if flag == True:
print(num)
3. Others' Solutions
import sys
import math
m,n = map(int,sys.stdin.readline().strip().split())
num_list = list(range(n+1))
for i in range(2, int(math.sqrt(n))+1):
if num_list[i] == 0:
continue
else:
for j in range(i+i,n+1,i):
num_list[j] = 0
for i in range(m, n+1):
if num_list[i] != 0 and num_list[i] > 1:
print(num_list[i])
4. Learned
1. Problem
2. My Solution
import sys
import math
while(True):
n = int(sys.stdin.readline().strip())
if n == 0:
break
nn = n * 2
prime_list = [True for i in range(nn+1)]
for i in range(2,int(math.sqrt(nn))+1):
if prime_list[i] == False:
continue
for j in range(i+i,nn+1,i):
prime_list[j] = False
print(prime_list[n+1:nn+1].count(True))
3. Others' Solutions
import sys
import math
max_num = (123456 * 2)
prime_list = [True for i in range(max_num+1)]
for i in range(2,int(math.sqrt(max_num))+1):
if prime_list[i] == False:
continue
for j in range(i+i,max_num+1,i):
prime_list[j] = False
while(True):
n = int(sys.stdin.readline().strip())
if n == 0:
break
nn = n * 2
count = 0
for i in range(n+1, nn+1):
if prime_list[i] == True:
count += 1
print(count)
4. Learned
1. Problem
2. Others' Solutions
import sys
import math
num_list = [True for i in range(10001)]
for i in range(2,int(math.sqrt(10000))+1):
if num_list[i] == False:
continue
for j in range(i+i,10001,i):
num_list[j] = False
test_n = int(sys.stdin.readline().strip())
for i in range(test_n):
n = int(sys.stdin.readline().strip())
for i in range(n//2,1,-1):
if num_list[i] == True and num_list[n-i]==True:
print(i, n-i)
break
3. Learned
1. Problem
2. Others' Solutions
import sys
x_list = []
y_list = []
for i in range(3):
x,y = map(int,sys.stdin.readline().strip().split())
x_list.append(x)
y_list.append(y)
for i in range(3):
if x_list.count(x_list[i]) == 1:
x = x_list[i]
if y_list.count(y_list[i]) == 1:
y = y_list[i]
print(x,y)
3. Learned