P7540

· · 题解

一道简单的结论题。手玩几组数据得到所有的数对组数为\tfrac{(n+1)*(n+2)}{2},

再一求和,发现答案就是\tfrac{n*(n+1)*(n+2)}{2}

所以,对于这道题,我们只要O(1)输出答案即可

Code
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    cout<<(n*(n+1)*(n+2)>>1)<<'\n';//右移一位相当于/2,但运行速度更快
    return 0;
}