Đếm viên bi

View as PDF

Submit solution

Points: 100.00 (partial)
Time limit: 1.0s
Memory limit: 256M
Input: stdin
Output: stdout

Suggester:
Problem type

Trong cuộc thi sắp những viên bi thành hình tam giác đều. Biết rằng chỉ cần chiều dài của cạnh tam giác thì sẽ biết được tổng các viên cần thiết để sắp xếp. Bài toàn được mô tả như sau:

Dữ liệu vào:

số nguyên n (n ≤ ~10^{18}~).

Dữ liệu ra:

là số nguyên đếm được.

Ví dụ:

Input

6

Output

21

Comments

Please read the guidelines before commenting.



  • 0
    tcu_06   commented on Aug. 23, 2025, 8:33 p.m.

    include <iostream>

    using namespace std;

    int main() { int n; cout << " "; cin >> n;

    int tong = 0;
    for (int i = 1; i <= n; i++) {
        tong += i;
    }
    
    cout << " " << tong << endl;
    
    return 0;
    

    }


  • 0
    tcu_18   commented on Aug. 23, 2025, 8:09 p.m.

    include <iostream>

    using namespace std;

    int main() { long n, sum = 0; cout << "nhap n:"; cin >> n;

    for (int i = n - 1; i >= 0; i--){
        sum += 1;
        }
    
    cout << "so bi" << n - 1 << sum << endl;
    
    return 0;
        }