25 lines
493 B
Java
25 lines
493 B
Java
package LanQiaoOJ;
|
||
|
||
import java.util.Scanner;
|
||
//方法:暴力破解——时间复杂度为O(n^2)
|
||
//范围为2e5*2e5=4e10 超时
|
||
public class 求和2 {
|
||
static int N=200010;
|
||
static long[]a=new long[N];
|
||
public static void main(String[] args) {
|
||
Scanner sc=new Scanner(System.in);
|
||
int n=sc.nextInt();
|
||
for(int i=1;i<n;i++) {
|
||
a[i]=sc.nextInt();
|
||
}
|
||
long ans=0;
|
||
for(int i=1;i<=n;i++) {
|
||
for(int j=i+1;j<=n;j++) {
|
||
ans+=a[i]+a[j];
|
||
}
|
||
}
|
||
System.out.println(ans);
|
||
}
|
||
|
||
}
|