• 数论推公式


     

    Print the answer.

    Sample Input 1

     

    3
    2 8 4
    

    Sample Output 1

     

    56
    

    We have Ni=2i1j=1(AiAj)^2=(82)^2+(42)^2+(48)^2=56.

    Sample Input 2

     

    5
    -5 8 9 -4 -3
    

    Sample Output 2

     

    950


    这个题是个推公式题,看这个数据范围暴力肯定wa

    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+100;
    int n;
    ll a[maxn];
    ll ai[maxn];
    ll aj[maxn];
    ll sum[maxn];
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            sum[i]=sum[i-1]+a[i];
        }
        ll sum1=0;
        ll sum2=0;
        ll sum3=0;
        for(int i=2;i<=n;i++){
            sum1+=(a[i]*a[i]*(i-1));
        }
        for(int i=1;i<=n;i++){
            sum2+=(a[i]*a[i]*(n-i)); 
        }
        for(int i=2;i<=n;i++){
            sum3+=2*(a[i]*sum[i-1]);
        }
        cout<<sum1+sum2-sum3<<endl;
    }
  • 相关阅读:
    决策树分类
    集群服务器 获取COOKIE错误
    React 自写Loading
    HTB-靶机-Unattended
    HTB-靶机-LaCasaDePapel
    HTB-靶机-FriendZone
    HTB-靶机-CTF
    HTB-靶机-FluJab
    HTB-靶机-Help
    HTB-靶机-Chaos
  • 原文地址:https://www.cnblogs.com/lipu123/p/14513447.html
Copyright © 2020-2023  润新知