http://poj.org/problem?id=2000
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc,char **argv){
int days;
int coins;
int n2 = 0;
scanf("%d",&days);
while(days>0){
coins = 0;
n2 = (sqrt(1+8*days)-1)/2;
/*
for (int i = 1;i<=n2;i++){
coins += i*i;
}
*/
coins = n2*(n2+1)*(2*n2+1)/6;
coins += (n2+1)*(days-(1+n2)*n2/2);
printf("%d %d\n",days,coins);
scanf("%d",&days);
}
return 0;
}