BUPT-homework/pset3/3-sum.c
2021-10-12 17:07:06 +08:00

25 lines
381 B
C

#include <stdio.h>
int main(void) {
// Initialize variables and get input
long long sum = 0;
long long n;
scanf("%lld", &n);
// if n is smaller than 3
if (n < 3) {
printf("0\n");
return 0;
}
// Iterate through all
for (long long i = 3; i <= n; i++) {
sum += i * (i - 1) * (i - 2);
}
// Print the result
printf("%lld\n", sum);
return 0;
}