VL02 - Tính tổng S = 1 + 2 + 3 + ... + n

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
C, C#, C++, Go, Java, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift
  • Tính:

$$S = 1 + 2 + 3 + ... + n$$

Input

  • Số nguyên dương ~n (1 \le n \le 10^9)~

Output

  • Số nguyên dương ~S~ cần tìm.

Sample

Input #1
5
Output #1
15

Comments

Please read the guidelines before commenting.



  • 0
    tmhp369  commented on May 9, 2025, 1:55 a.m.

    n = int(input())

    if n < 0: print("Không tính tổng cho n âm") else: s = (n + 1) * n // 2 print(s)


  • 1
    kietjumper  commented on Oct. 20, 2024, 4:00 p.m.

    ~S = 1 + 2 + 3 + ... + n~

    ~→~ ~S~ ~=~ ~(n+1)~ * ~n~ / ~2~


  • -2
    giabao2016  commented on Oct. 12, 2024, 2:14 p.m. edited

    khó quá 5 nó cho ra kết quả kết quả bằng 15 mà có đúng có hai cái AC chứ máy??????????không biết ai chỉ cho tôi với huhuhuhuhuhuhuhuhuhu


  • 2
    super_god  commented on Oct. 8, 2024, 2:51 a.m.

    hello ae


  • 1
    giabao2015  commented on Oct. 5, 2024, 11:41 a.m.

    làm sao để đúng các bạn gửi ở gia bảo2015 nha please!helpppppppppppppppppppppppppp!


  • -2
    nickisawesome  commented on Aug. 5, 2024, 3:19 a.m.

    hao no


  • -2
    ngkhacbaolam2809  commented on Aug. 16, 2023, 7:52 a.m.

    mình chạy code trong VS Đúng mà test trên web lại sai =)))))


    • -2
      DucThanh_369  commented on Aug. 22, 2023, 1:37 p.m.

      De n la' long long moi ac