This is an easy problem from uva judge http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3301
Ad hoc.
How I did it
- Generate all the possibles scenarios
- Read the size of the square.
- Print the result.
Hints
- There is a pattern.
- The size is really small.
Code
#include <iostream> #include <cstdio> using namespace std; int vec[120], out[120]; void generate() { int increment = 3; vec[0] = 1; out[0] = 1; for(int x=1; x<=102; x++, increment = increment + 2) { vec[x] = vec[x-1] + increment; out[x] = out[x-1] + vec[x]; } } int main() { int num; generate(); while(scanf("%d", &num)) { if(!num) break; printf("%d\n", out[num-1]); } return 0; }