文章目录
- 数列求和
- 质数口袋
- 奇怪数求和
数列求和
n = int(input())
print(sum([i for i in range(1,n + 1)]))
质数口袋
n = int(input())
i = 2
sum = 0
count = 0
while n - i >= sum:
flag = True
for j in range(2,i): # 判断i是否为素数
if i % j == 0:
flag = False
break
if flag:
sum += i
print(i)
count += 1
i += 1
print(count)
奇怪数求和
n = int(input())
res = []
for i in range(1,n + 1):
if '2' in str(i) or '0' in str(i) or '3' in str(i) or '8' in str(i):
res.append(i)
print(sum(res))