Back to the Training Home
Back to the Training Home
Lesson: 35
Problem: 2538
Title: Triangular Sums
Difficulty Level: 2.0
Date: MAR 02, 2009
Site: http://acm.tju.edu.cn/toj/showp2538.html
Not a hard problem at all. At first generate all results and save it into an array.
#include<stdio.h>
#define maxn 1001
int Result[maxn];
void getResult() {
int i, sum = 3, total = 0;
for(i = 1; i<maxn; i++) {
total += i*sum;
Result[i] = total;
sum += (i + 2);
}
}
int main() {
int kase, k = 1, n;
getResult();
scanf("%d",&kase);
while(kase--) {
scanf("%d",&n);
printf("%d %d %d\n",k++,n,Result[n]);
}
return 0;
}
|