def expand(n): #expanding (9 + 4sqrt(5))^n into rational and irrational part #rational part rat_res = 0 irrat_res = 0 for k in range(0, n + 1, 2): rat_res += nChoosek(n, k) * 9**(n-k) * 4**k * 5**(k//2) for k in range(1, n + 1, 2): irrat_res += nChoosek(n, k) * 9**(n-k) * 4**k * 5**((k-1)//2) return rat_res, irrat_res
def expand(n): #expanding (a + bsqrt(c))^n into rational and irrational part #rational part a = 9 b = 4 c = 5 rat_res = 0 irrat_res = 0 for k in range(0, n + 1, 2): rat_res += nChoosek(n, k) * a**(n - k) * b**k * c**(k // 2) for k in range(1, n + 1, 2): irrat_res += nChoosek(n, k) * a**(n - k) * b**k * c**((k - 1) // 2) return rat_res, irrat_res
def count_incr(exp_10): return nChoosek(10 + exp_10 - 1, exp_10)
# -*- coding: utf-8 -*- """For any subset pairs of size i there are n choose 2i ways to choose the 2i members, and (2i-1) choose (i-2) ways to distribute the members of """ from eulerTools import nChoosek from datetime import datetime startTime = datetime.now() n = 12 resSum = 0 for i in range(2, n // 2 + 1): resSum += nChoosek(n, 2 * i) * nChoosek(2 * i - 1, i - 2) print("result = " + str(resSum)) print(datetime.now() - startTime)
def square_calc(l, w): if l == 0 or w == 0: return 0 return nChoosek(l + 1, 2) * nChoosek(w + 1, 2)
return 0 return nChoosek(l + 1, 2) * nChoosek(w + 1, 2) startTime = datetime.now() start = timer() square_arr = [0 for i in range(44)] hard_square_arr = [0 for i in range(44)] for idx in range(2, 44): count = 0 length = 2 * (idx - 1) width = 2 while length > width: count += 2 * nChoosek(length + 1, 2) * nChoosek(width + 1, 2) length -= 2 width += 2 if length == width: count += nChoosek(length + 1, 2)**2 hard_square_arr[idx] = count count -= hard_square_arr[idx - 1] square_arr[idx] = count res = 0 for a in range(43 + 1): res += square_arr[a] res += square_calc(a, a) base_count = 0 for x in range(1, 2 * a):