10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?

题目:10177 - (2/3/4)-D Sqr/Rects/Cubes/Boxes?


题目大意:求一维,二维,三维n面体(形)分别有多少个正方形(体),和矩形(不含正方形(体))(对于一二维来说,三维类似)。

解题思路:正方形个数 sum(pow(i, 维数+ 1)),i从1……n。矩形pow(n*(n+1) / 2, 维数+1)- 同维数的正方体个数。


#include<stdio.h>
#include<string.h>
#include<math.h>

const int N = 4;
long long s[N], q[N];
long long n;

int  main() {
	
	while(scanf("%lld", &n) != EOF) {
		int  i, j;
		memset(s, 0, sizeof(s));
		memset(q, 0, sizeof(q));
		for( i = 1; i <= 3; i++) {
			for( j = 1; j <= n; j++) 
				s[i] += pow(j, i + 1);
			
		}
	
		long long  k = n * (n + 1) /2;
		for(i = 1; i <= 3; i++) {

			q[i] = pow(k, i + 1) - s[i];

		}
		for( i = 1; i <= 3; i++) {
			if(i != 3)
				printf("%lld %lld ", s[i], q[i] );
			else
				printf("%lld %lld\n", s[i], q[i]);

		}
	}
	return 0;
}


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