Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- def numAt(a, b):
- if(a == 1 or b ==1 ):
- return 1
- elif(a == b):
- return 1
- else:
- return numAt(a-1,b-1)+numAt(a-1,b)
- def printTuple(a):
- first = str(a[0])
- second = str(a[1])
- print(first + ' ' + second)
- def printTuples(a):
- for b in a:
- printTuple(b)
- def debugSumTuples(a):
- sum = 0
- for i in a:
- sum+=addTuple(i)
- return sum
- def addTuple(a):
- return numAt(a[0],a[1])
- def solve(target, line):
- sum = line - 1
- lastOfLine = 0
- remainder = 0
- for i in range (1, line+1):
- oldsum = sum
- sum+= numAt(line,i)
- if sum == target:
- lastOfLine=i
- remainder = 0
- break
- if sum>target:
- lastOfLine = i-1
- remainder = target - oldsum
- if(remainder > line):
- return solve(target,line+1)
- break
- returnList = [(1,1)]
- for i in range (2, line):
- if i-1 == remainder and remainder != 0:
- returnList.append((i,2))
- returnList.append((i,1))
- for i in range (1, lastOfLine+1):
- returnList.append((line,i))
- return returnList
- numtests = input()
- for i in range(1, int(numtests) + 1):
- num = int(input())
- firstTuple = (1, 1)
- listTuples = []
- listTuples.append(firstTuple)
- if(num == 1):
- print("Case #" + str(i) + ":")
- printTuples(listTuples)
- else:
- sum = 1
- for j in range(2, 500):
- hypothetical = sum + 2**(j-1)
- if hypothetical > num:
- newList = solve(num, j)
- print("Case #" + str(i) + ":")
- printTuples(newList)
- #print("Sum: " + str(debugSumTuples(newList)))
- break
- else:
- sum+=1
Advertisement
Add Comment
Please, Sign In to add comment