UVa 11028 Sum of Product (A007773,你懂的)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1969


算了前几个发现是A007773

还给出了个公式:当n>=7, a(n) = (n^3-16n+27)/6 (n是奇数); (n^3-16n+30)/6 (n是偶数).(这谁看的出来!)


完整代码:

/*0.012s*/

#include<cstdio>
const int a[] = {0, 1, 1, 1, 3, 8, 21, 43, 69, 102, 145, 197, 261, 336, 425, 527, 645, 778, 929, 1097, 1285};

int main()
{
	int n, cas = 0;
	while (scanf("%d", &n), n)
		printf("Case #%d: %d\n", ++cas, a[n]);
	return 0;
}

你可能感兴趣的:(C++,ACM,uva)