UVA 10177 (暑假-数学(3) -D - (2/3/4)-D Sqr/Rects/Cubes/Boxes?)

#include <cstdio>

int main() {
	int n;
	while (scanf("%d", &n) != EOF) {
		long long s2 = 0, s3 = 0, s4 = 0, r2, r3, r4;
		long long m = n * (n + 1) / 2;
		r2 = m * m;
		r3 = m * m * m;
		r4 = m * m * m * m;
		while (n) {
			s2 += n*n;
			s3 += n*n*n; 
			s4 += n*n*n*n;
			n--;
		}
		printf("%lld %lld %lld %lld %lld %lld\n", s2, r2-s2, s3, r3-s3, s4, r4-s4);
	}
	return 0;
}

你可能感兴趣的:(UVA 10177 (暑假-数学(3) -D - (2/3/4)-D Sqr/Rects/Cubes/Boxes?))