python 第三组WA了

P2669 [NOIP2015 普及组] 金币

Wangrh @ 2024-01-20 22:49:44

k = int(input())
s = 0
for i in range(k//2, 0, -1):
    if i*(1+i)//2 <= k:
         t = k-(i*(1+i)//2)
         for j in range(1, i+1):
             s += pow(j, 2)
         s += t*(i+1)
         break
    else:
        continue
print(s, end='')

by 70CentsApple @ 2024-01-21 00:06:46

特殊判断 k=1 的情况 @Wangrh


by Wangrh @ 2024-01-21 17:39:04

@70CentsApple 通过了,谢谢佬


by 1em0ns @ 2024-03-10 20:34:30

来看个简洁的

day = int(input())

list=[]
i = 1
k=0
while(k<day):
    for t in range(i):
        list.append(i)
        k+=1
    i+=1
print(sum(list[:day]))

|