[蓝桥杯 2022 省 A] 求和

Luogu
IDLGP8772
Time1000ms
Memory128MB
DifficultyP2
2022前缀和差分蓝桥杯省赛
给定 $n$ 个整数 $a_{1}, a_{2}, \cdots, a_{n}$, 求它们两两相乘再相加的和,即 $$ S=a_{1} \cdot a_{2}+a_{1} \cdot a_{3}+\cdots+a_{1} \cdot a_{n}+a_{2} \cdot a_{3}+\cdots+a_{n-2} \cdot a_{n-1}+a_{n-2} \cdot a_{n}+a_{n-1} \cdot a_{n} $$ ## Input 输入的第一行包含一个整数 $n$ 。 第二行包含 $n$ 个整数 $a_{1}, a_{2}, \cdots a_{n}$ 。 ## Output 输出一个整数 $S$,表示所求的和。请使用合适的数据类型进行运算。 [samples] ## Note 对于 $30 \%$ 的数据, $1 \leq n \leq 1000,1 \leq a_{i} \leq 100$ 。 对于所有评测用例, $1 \leq n \leq 2\times10^5,1 \leq a_{i} \leq 1000$ 。 蓝桥杯 2022 省赛 A 组 C 题。
Samples
Input #1
4
1 3 6 9
Output #1
117
API Response (JSON)
{
  "problem": {
    "name": "[蓝桥杯 2022 省 A] 求和",
    "description": {
      "content": "给定 $n$ 个整数 $a_{1}, a_{2}, \\cdots, a_{n}$, 求它们两两相乘再相加的和,即 $$ S=a_{1} \\cdot a_{2}+a_{1} \\cdot a_{3}+\\cdots+a_{1} \\cdot a_{n}+a_{2} \\cdot a_{3}+\\cdots+a_{n-2} \\cdot a_{n-1}+a_{n-2} \\cdot a_{n}+a_{n-1} \\",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 131072
    },
    "difficulty": {
      "LuoguStyle": "P2"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP8772"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定 $n$ 个整数 $a_{1}, a_{2}, \\cdots, a_{n}$, 求它们两两相乘再相加的和,即\n\n$$\nS=a_{1} \\cdot a_{2}+a_{1} \\cdot a_{3}+\\cdots+a_{1} \\cdot a_{n}+a_{2} \\cdot a_{3}+\\cdots+a_{n-2} \\cdot a_{n-1}+a_{n-2} \\cdot a_{n}+a_{n-1} \\...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments