import math """ def return_sum(result): sum = 0 for i,j in result: sum += ptc[i-1][j-1]
return sum def combination(n, r): return int((math.factorial(n)) / ((math.factorial(r)) * math.factorial(n - r)))""" """ def pascals_triangle(rows): result = [] for count in range(rows): row = [] for element in range(count + 1): row.append(combination(count, element)) result.append(row) return result""" #ptc = pascals_triangle(50) ptc = [i+1 for i in range(50)] t = int(input()) for t in range(t): n = int(input()) if n <= 30: result = [[i,1] for i in range(1,n+1)] #print(result) else: result = [] left = True bin = '{0:b}'.format(n-30)[-1::-1] zeros = bin.count('0') current_row = 0 #print(zeros) for i,bit in enumerate(bin): if bit == '1' and left: for c in range(ptc[i]): result.append([i+1,c+1]) left = False current_row = i+1 elif bit == '1' and not left: for c in range(ptc[i],0,-1): result.append([i+1,c]) left = True current_row = i+1 else: if left: result.append([i+1,1]) current_row = i+1 else: result.append([i+1,ptc[i]]) current_row = i+1 for c in range(30-zeros): if left: result.append([current_row+c+1,1]) else: result.append([current_row+c+1,ptc[current_row+c]]) print("Case #{}:".format(t+1)) for i,j in result: print(i,j,sep = " ") #print(return_sum(result)) -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-code+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/3a48fa41-f456-411e-9a20-bc2c0dbb7567%40googlegroups.com.