Skip to content

Instantly share code, notes, and snippets.

@nmakeenkov
Created October 10, 2019 09:02
Show Gist options
  • Save nmakeenkov/4b7ef7abfd2a03e5809673415c58ef49 to your computer and use it in GitHub Desktop.
Save nmakeenkov/4b7ef7abfd2a03e5809673415c58ef49 to your computer and use it in GitHub Desktop.
4 numbers
def get_easy_res(n):
ans = 0
for a in range(1, n):
for b in range(1, n):
for c in range(1, n):
d = n - a - b - c
if d <= 0 or a == b or a == c or a == d or b == c or b == d or c == d:
continue
ans += 1
return ans
def get_formula_res(n):
res = (n - 6) * (n - 5) * (2 * n - 11) // 6
res += 7 * (n - 6) * (n - 5) // 2
res += 12 * (n - 6)
res //= 2
pair_count = (2 * ((n - 1) // 2) - 6) // 2
res -= 6 + 3 * pair_count * (3 + 3 + pair_count - 1)
if (n - 1) % 2 == 1:
res -= 3 * (n - 2) // 2
res += ((n - 6) // 3 + 1) * 2
T = (n - 3) // 2
ss = T * (n - T - 2)
if n % 2 == 0:
ss -= T
ss -= 2 * ((n - 1) // 3)
if n % 4 == 0:
ss += 2
res -= 3 * ss
if n % 3 == 0:
res -= 2
return res
for n in range(10, 150):
er = get_easy_res(n)
hr = get_formula_res(n)
if er != hr:
print('fail', n, er, hr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment