家人们,已经是90了,但是第三组异常了,请求帮助!!!Python语言

P2669 [NOIP2015 普及组] 金币

Shenxinxin @ 2023-02-25 16:18:24

x=int(input()) s=0 d=0 if 1<=x<=104: for i in range(1,x): while d<x: d+=i b=i break h=d-x if h==0: for i in range(1,b+1): s+=i2 print(s) else: for i in range(1,b+1): s+=i*2 s-=hb print(s)


by Shenxinxin @ 2023-02-25 17:04:50

@A_Passing_Creeper 是的,是PY,问题已经解决了,我忘记x=1的情况了,谢谢了


by Shenxinxin @ 2023-02-25 17:05:48

@SPRINT_NOIP 谢谢谢谢大佬


by SPRINT_NOIP @ 2023-02-25 17:05:58

x = int(input())
s = 0
d = 0
if 1 <= x <= 10 ** 4:
    for i in range(1, x + 1):
      while d < x:
        d += i
        b = i
        break
    h = d - x
    if h == 0:
      for i in range(1, b + 1):
        s += i ** 2
      print(s)
    else:
      for i in range(1, b + 1):
        s += i ** 2
      s -= h * b
      print(s)

by SPRINT_NOIP @ 2023-02-25 17:07:43

x = int(input())
s = 0
d = 0
if 1 <= x <= 10 ** 4:#这行可以不用打
    for i in range(1, x + 1):#这里要加1,以便取到1
      while d < x:
        d += i
        b = i
        break
    h = d - x
    if h == 0:
      for i in range(1, b + 1):
        s += i ** 2
      print(s)
    else:
      for i in range(1, b + 1):
        s += i ** 2
      s -= h * b
      print(s)
x = int(input())
s = 0
d = 0
   for i in range(1, x + 1):
     while d < x:
       d += i
       b = i
       break
   h = d - x
   if h == 0:
     for i in range(1, b + 1):
       s += i ** 2
     print(s)
   else:
     for i in range(1, b + 1):
       s += i ** 2
     s -= h * b
     print(s)

by SPRINT_NOIP @ 2023-02-25 17:09:09

@Shenxinxin

下面的是完整代码


by SPRINT_NOIP @ 2023-02-25 17:10:12

@Shenxinxin

不用谢

也帮我回忆了python

嘻嘻


by Shenxinxin @ 2023-02-25 17:10:16

@SPRINT_NOIP 懂了懂了大佬,感谢感谢,醍醐灌顶


上一页 |