poj 3086 Triangular Sums

#include <iostream>
using namespace std;

int w(int n)
{
    int sum = 0, i;
    for (i = 1; i <= n+1; i++)
        sum += i;
    return sum;
}

int main()
{
    int tc, n, i, c = 0, ans;
    cin >> tc;
    while (tc--){
          cin >> n;
          c++;
          ans = 0;
          for (i = 1; i <= n; i++){
              ans += i * w(i);
          }
          cout << c << " " << n << " " << ans << endl;
    }
    
    system("pause");
}

你可能感兴趣的:(poj 3086 Triangular Sums)