BUPT-homework/pset3/3-sum.c

25 lines
381 B
C
Raw Normal View History

2021-10-12 13:18:54 +08:00
#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) {
2021-10-12 17:04:08 +08:00
printf("0\n");
2021-10-12 13:18:54 +08:00
return 0;
}
// Iterate through all
2021-10-12 17:04:08 +08:00
for (long long i = 3; i <= n; i++) {
2021-10-12 13:18:54 +08:00
sum += i * (i - 1) * (i - 2);
}
// Print the result
printf("%lld\n", sum);
return 0;
}