fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int a[150],sum;
  4. int main(){
  5. ios::sync_with_stdio(false);
  6. cin.tie(0),cout.tie(0);
  7. int n;
  8. cin>>n;
  9. for(int i=0;i<n;i++){
  10. sum+=(n-i)*(i+1);
  11. }
  12. cout<<sum;
  13. return 0;
  14. }
Success #stdin #stdout 0.01s 5320KB
stdin
4
stdout
20