题解 | 小红的“质数”寻找
小红的“质数”寻找
https://www.nowcoder.com/practice/0b98a50ea30e4a3a9fe08a46eeb5f7fc
观察数字范围的分布可以得出,只需枚举数位和为质数的最小代表数(2,3,5,7,11),并通过不断乘 10 将其映射至 [x,2x]区间内,即可保证构造合法
t = int(input())
ans = [2,3,5,7,11]
for _ in range(t):
x = int(input())
f = False
for i in ans :
k = i
y = x*2
if f :
break
while k<=y :
if x<=k<=y :
print(k)
f = True
break
k *= 10
if not f :
if x<=11<=x*2:
print(11)
查看12道真题和解析