def solve53(D, L): count = 0 for n in range(2, L+1): for r in range(1, n/2): if choose(n, r) > D: count += n + 1 - 2*r break return count
def BDexpected(k, n, lam, mu) : """ Expected k'th speciation time for birth/death tree conditioned on n taxa. k == 1 is root. """ #Have serious numerical issues for small mu, so code is using #'Decimal', which unfortuanetly complicates the code. if mu == 0 : return sum([1/i for i in range(k+1, n+1)])/lam if mu == lam: return (n-k)/(lam*k) mu,lam = Decimal(str(mu)), Decimal(str(lam)) r = mu/lam s1 = sum([_f1(r,k,i) * choose(n-k-1, i)*(1/r -1)**(k+i)/((k+i+1)*r) for i in range(n-k)]) return float(Decimal(str(((k+1)/lam) * choose(n, k+1) * (-1)**k)) * s1)
def subtree_leq(self, m, tg, root=True): if root: if not self.rootmonoleq(m, tg): return False else: if not self.monoleq(m, tg): return False for tg_linkset in choose(tg.links(), len(m.links())): for ii, jj in itermatchings( m.links(), tg_linkset, lambda i, j: self.linkleq(i, j) and self.subtree_leq(i.child(), j.child(), root=False)): return True return False
def info ( M , m , n ) : # fill M # we assume that for all j > i --> ai < aj and bi < bj # M[i][j] = -1 means ai < bj # M[i][j] = 1 means ai > bj # M[i][j] = 0 means ai and bj are incomparable # generate random info positions = sorted( choose( m + n , m ) ) for i , j in enumerate( positions ) : M[i][:j-i] = [ 1 ] * ( j - i ) M[i][j-i:] = [ -1 ] * ( n - j + i ) return M
def info(M, m, n): # fill M # we assume that for all j > i --> ai < aj and bi < bj # M[i][j] = -1 means ai < bj # M[i][j] = 1 means ai > bj # M[i][j] = 0 means ai and bj are incomparable # generate random info positions = sorted(choose(m + n, m)) for i, j in enumerate(positions): M[i][:j - i] = [1] * (j - i) M[i][j - i:] = [-1] * (n - j + i) return M
# # # # # # # # Author phantomhive # # 26-07-2019 # # # # # # # # from collections import Counter, deque, defaultdict from math import ceil, floor, sqrt, log, factorial from fractions import Fraction, gcd from sys import stdin, stdout from bisect import bisect, bisect_left, bisect_right from heapq import heapify, heappop, heappush, heappushpop from combinatorics import choose from time import time def lcm(a, b): return (a * b) / gcd(a, b) cin, cout = stdin.readline, stdout.write # Start time START = time() ans = 7 * (1 - (choose(60, 20) / float(choose(70, 20)))) cout("Probability : %.9f\n" % ans) # End Time END = time() seconds = END - START print("Total time %d minutes %d seconds" % (seconds / 60, seconds % 60))
def _f1(r,k,i) : return (1/(1-r)).ln() - \ sum([(1-(1/(1-r))**j)*choose(k+i,j)*(-1)**j/j for j in range(1,k+i+1)])
from math import ceil, floor, sqrt, log, factorial from fractions import Fraction, gcd from sys import stdin, stdout from bisect import bisect, bisect_left, bisect_right from heapq import heapify, heappop, heappush, heappushpop from time import time from combinatorics import choose def lcm(a, b): return (a * b) / gcd(a, b) cin, cout = stdin.readline, stdout.write # Start time START = time() LIMIT, COUNT = 5000, 2000000 n_, m_, abs_diff = 0, 0, COUNT for n in xrange(LIMIT): for m in xrange(LIMIT): count = choose(n + 1, 2) * choose(m + 1, 2) if abs_diff > abs(count - COUNT): n_, m_ = n, m abs_diff = abs(count - COUNT) cout('Area of required rectangle is: %d\n' % (n_ * m_)) # End Time END = time() seconds = END - START print("Total time %d minutes %d seconds" % (seconds / 60, seconds % 60))
def nForestRankedTopologies(n1, n2, k) : """ Number of ranked histories of a labeled forest with 1+k trees, the first tree on n1 taxa, the remaining k on a total of n2 taxa. """ return choose(n1+n2-k-2, n1-2) * prod([long(c2(x)) for x in range(3, n1+1) + range(k+1, n2+1)])