12345678910111213
int op_limit = 1; int op_done = 0; bool add = true; int sum = 0; for(int i = 1; i <= n; ++i) { if(op_done == op_limit) { op_done = 0; ++op_limit; add = !add; } sum += (add? t : -t); ++op_done; }