uva 10177

 1 #include<stdio.h>
 2 #include<math.h>
 3 int main()
 4 {
 5    long long s2 , r2 , s3 , r3 , s4 , r4 , n ;
 6    while( scanf("%lld" ,  &n) == 1 )
 7    {
 8        s2 = n * ( n + 1 ) * ( 2 * n + 1) / 6 ;
 9        s3 = n * n * ( n + 1 ) * ( n + 1 ) / 4  ;
10        s4 = n * ( n + 1 ) * (2 * n + 1) * ( 3 * n * n + 3 * n - 1) / 30  ;
11 
12        r2 = n * n * ( n + 1 ) * ( n + 1 ) / 4  - s2;
13        r3 = n * n * n * (n+1) * (n+1) * (n+1) / 8 - s3;
14        r4 = n * n * n * n * (n+1) * (n+1) * (n+1) * (n+1) / 16 - s4;
15        printf("%lld %lld %lld %lld %lld %lld\n", s2 , r2, s3, r3, s4 , r4) ;
16    }
17     return 0 ;
18 }

先分析二维情况:squares 数为 ∑n = n * ( n + 1 ) * ( 2 * n + 1) / 6

        矩形总数为 ( n * (n+1) / 2)

三维:squares 数为 ∑n3

        矩形总数为 ( n * (n+1) / 2)3 

posted @ 2013-11-19 22:01  shaughn  阅读(139)  评论(0编辑  收藏  举报