public static int day(int sum, int n, int d) { int test = n * (n - 1) / 2; int test2 = (sum - test) % n; if (test2 == 0) { return (sum - test) / n; } else { return day(sum - d - 1, n - 1, d + 1); } }