LanQiaoTestCodes/求和2.java

25 lines
493 B
Java
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}