Python Code:
n=int(input('輸入上限值:'))
m1=str(input('輸入第一次欲扣除的數字:'))
#m2=str(input('輸入第二次欲扣除的數字:'))
a = [str(i) for i in range(1,n+1)]
b=[]
for k in a:
for i in range(len(k)):
if k[i]==m1:
b.append(k)
c=set(a)-set(b)
c=[int(x) for x in c]
c=sorted(c)
print(c)#印出該數列
print(c.index(111))
print(c[2021-1])#列印出某一項
sum=0#求前n項的數字總和
for i in range(2021):
sum+=c[i]
print(sum)