天天看点

Feynman

// http://www.spoj.com/problems/SAMER08F/


#include <iostream>


using std::cin;
using std::cout;
using std::endl;

int solve(int n) {
	int total = 0;
	if (n == 1) {
		total = 1;
	} else {
		total = 0;
		for (int i = 1; i <=n; i++) {
			total += (n - i + 1) * (n - i + 1);
		}
	}
	return total;
}
int main(int argc, char* argv[]) {
	int n;
	cin >> n;

	while (n !=0 ) {
		cout << solve(n) << endl;
		cin >> n;
	}
}
           

继续阅读