這兩題均使用Python3編寫
第一題
num10 = int(input())
num4 = []
if num10 < 4:
print(num10)
else:
while num10 > 3:
num4.append(str(num10 % 4))
num10 = num10 // 4
if num10 > 0:
num4.append(str(num10))
num4 = ''.join(reversed(num4))
print(num4)
第二題
import itertools
num = int(input())
count = 0
# 判斷是否為素數(shù)的函數(shù)
def isSushu(n):
for i in range(2,n):
if n%i==0:
return 0
return 1
# 得到素數(shù)列表
s = []
for i in range(2,num+1):
if isSushu(i):
s.append(i)
# 獲得素數(shù)對
b = list(itertools.combinations(s, 2))
for i in range(len(b)):
if sum(b[i])==num:
count += 1
for i in s:
if 2*i == num:
count += 1
print(count)
這兩題通過了全部示例。