问题描述
输入格式
输出格式
输出一个整数 S,表示所求的和。请使用合适的数据类型进行运算。
样例输入
4
1 3 6 9
样例输出
117
评测用例规模与约定
运行限制
- 最大运行时间:1s
- 最大运行内存: 512M
题解:
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
long[] array = new long[200000];
long sum = 0;
long res = 0;
for(int i = 0;i < n; i++){
array[i] = scan.nextLong();
sum += array[i];
}
for(int i = 0;i < n;i++){
sum -= array[i];
res += sum*array[i];
}
System.out.print(res);
scan.close();
}
}