[HDU] [2007] Sum of Squares and Sum of Cubes

Problem Description

Loading...

Problem Analysis

Nothing much to say…
Looking at this code now, there’s still room for optimization
Keep it in mind next time I run into something similar
By the way, didn’t we already cover this problem before…

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
int main() {
    int i,x,y,m,n;
    while(scanf("%d %d",&m,&n)!=EOF) {
        if(m>n) {
            i=m;
            m=n;
            n=i;
        }
        x=y=0;
        for(i=m; i<=n; i++) {
            if(i%2==0) {
                x=x+i*i;
            } else {
                y=y+i*i*i;
            }

        }
        printf("%d %d\n",x,y);
    }
    return 0;
}

Loading...