算法问题

沉默的牧羊者 沉默的牧羊者 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
Problem Description


Give you n elements a1, a2, a3,..., an.You need to calculate the sum of (a1 * a1 * a1 + a2 * a2 * a2 + ... + an * an * an).

Input


The first line of the input contains an integer T(1<=T<=10) which means the number of test cases.

Each case starts with a line containing a integers n(1 <= n <= 1,000).

The next line contains n space-separated elements ai (1 <= i <= n), and 0 <= ai <= 100,000.

Output

For each case, you need to print the answer in a single line.

Sample Input

2
2
1 1
3
2 4 7

Sample Output

2
415


这是一道ACM的训练题

以下是我的的代码

#include <iostream>

using namespace std;

int main()

{
int T;
cin >> T;
int T1 = T;
int a[1005],t;
int i,j = 0;
long long s[15] = { 0 };
while (T--)
{
cin >> t;
for (i = 0; i < t; i++)
{
cin >> a[i];
s[j] += a[i] * a[i] * a[i];
}
j++;
}
i = 0;
while (T1--)
{
cout << s[i] << endl;
i++;
}
return 0;
}
我调试的时候没有发现错误,内存方面longlong是支撑的起的,但是答案就是错的,不清楚为什么。
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
沉默的牧羊者
C++ 语言 65,212 成员 250,513 内容