예제 #1
0
def T(n):

    ntmax = n / 2
    tot = 0
    for i in xrange(ntmax):
        opentiles = n - i * 2
        c = nCr(n, opentiles)
        tot += c
        print n, i, opentiles, c, 10**opentiles
    return tot
예제 #2
0
def T(n):

  ntmax = n/2
  tot = 0
  for i in xrange(ntmax):
    opentiles = n - i*2
    c = nCr(n,opentiles)
    tot +=c
    print n,i,opentiles, c, 10**opentiles
  return tot
예제 #3
0
def Lucas(N,k,p):

  s1 = b10Tobm(N,p)
  s2 = b10Tobm(k,p)

  l = len(s1)
  if l>len(s2):
    sa = [0]*(l-len(s2))
    s2 = sa + s2

  v = 1
  for i in xrange(l):

    a = int(s1[i])
    b = int(s2[i])
    v *= nCr(a,b)

  v %= p

  return v
예제 #4
0
from Functions import nCr

summ = 0

for i in xrange(14):
    z = 2 * (i + 2) * (i + 1) * 16**i
    summ += z
    print z

print summ

summ2 = 0

for i in xrange(13):
    #z = 13*(i+3)*(i+2)*(i+1)*16**i
    z = 16 * nCr(i + 3, 3) * 16**i
    summ2 += z
    print z

print
print summ2
summ3 = 0

for k in xrange(3, 17):
    summ3 += 15 * 16**(k - 1) - 15**(k) - (2 * 14) * 15**(k - 1) + (
        13 * 14**(k - 1)) + 2 * 14**k - 13**k

# for i in xrange(3,17):
# summ2 +=43 * 15**(i - 1)* 13**i
# print
예제 #5
0
def R(n, m, k):
    return nCr(n, k) * subFactorial(m - k)
예제 #6
0

def subFactorial(n):
    summ = 0
    for x in xrange(n + 1):
        summ += float(pow(-1, x)) / factorial(x)
    return factorial(n) * summ


def R(n, m, k):
    return nCr(n, k) * subFactorial(m - k)


st = time()
z = 0.0
fixed = nCr(25, 3)
fact100 = factorial(100)

for k in xrange(23):
    z += R(75, 97, k) * fixed / fact100

print "Probability is ", z
print "time elapsed ", time() - st

# for m in xrange(1,7):
# print R(8,m)

# print R(25,22)

# print R(25,3)/factorial(25)
# print
예제 #7
0
#
#
#
#
#
from math import ceil
from Functions import nCr,RetFact
from time import time

st = time()

sf = {}

for r in xrange(0, 51):
  for c in xrange(1,int(ceil(r/2))+1): 
    v = nCr(r,c)
    if v in sf: continue
    facts = RetFact(v)
    setfacts = set(facts)
    if len(facts)>len(setfacts): continue
    sf[v]=v

print
#print sf
#print

print 1 + sum(sf)
print time()-st


예제 #8
0
def R(n,m,k):
  return nCr(n,k)*subFactorial(m-k)
예제 #9
0
from Functions import nCr
from math import factorial
from time import time

def subFactorial(n):
  summ = 0
  for x in xrange(n+1): summ += float(pow(-1,x))/factorial(x)
  return factorial(n) * summ
    
def R(n,m,k):
  return nCr(n,k)*subFactorial(m-k)
  
st =time() 
z = 0.0
fixed = nCr(25, 3)
fact100 = factorial(100)

for k in xrange(23):z += R(75,97,k) * fixed / fact100
 
print "Probability is ", z
print "time elapsed ", time()-st

# for m in xrange(1,7):
  # print R(8,m)
  
# print R(25,22)
 
# print R(25,3)/factorial(25)
# print
# for i in xrange(25,101):
예제 #10
0
from Functions import nCr

summ = 0

for i in xrange(14):
  z =  2*(i+2)*(i+1)*16**i
  summ += z
  print z
 
print summ

summ2 =0

for i in xrange(13):
  #z = 13*(i+3)*(i+2)*(i+1)*16**i
  z = 16*nCr(i+3,3)*16**i
  summ2 += z
  print z

print 
print summ2
summ3=0

for k in xrange(3,17):
  summ3+=15*16**(k-1)-15**(k)-(2*14)*15**(k-1)+(13*14**(k-1))+2*14**k-13**k

# for i in xrange(3,17):
  # summ2 +=43 * 15**(i - 1)* 13**i
# print

# summ -=summ2
예제 #11
0
from Functions import nCr

ctr = 0
for i in xrange(7, 200):
    print i, ";",
    ctr2 = 0

    if i % 2 == 1:
        dbl = True
        rng = int(i / 2.)
    else:
        dble = False
        rng = int(i / 2.)

    for j in xrange(1, rng + 1):
        #print nCr(i,j),
        x = nCr(i, j)
        if x % 7 == 0:
            #ctr +=1
            ctr2 += 1
        # print x
    if dbl:
        ctr2 *= 2
    else:
        ctr2 = ctr * 2
    ctr += ctr2
    print "***** ", i, ctr2
    print
print
print ctr
예제 #12
0
ctr=0
for i in xrange(7,200):
  print i,";",
  ctr2=0

  if i%2==1:
    dbl = True
    rng = int(i/2.)
  else:
    dble = False
    rng = int(i/2.) 
  
  for j in xrange(1,rng+1):
    #print nCr(i,j), 
    x=nCr(i,j)
    if x%7==0: 
      #ctr +=1
      ctr2 +=1
     # print x
  if dbl:
    ctr2 *=2 
  else:
    ctr2 =ctr*2 
  ctr += ctr2
  print "***** ",i,ctr2
  print
print
print ctr

예제 #13
0
def R(n,k):
  return nCr(n,k)*subFactorial(n-k)
예제 #14
0
    summ += float(pow(-1,x))/factorial(x)
	
  return factorial(n) * summ
    
st =time()


def R(n,k):
  return nCr(n,k)*subFactorial(n-k)
 
z = 0.0


for k in xrange(23):
  #z +=  (-1.0)**k * nCr(22, k) * factorial(97 - k) * nCr(25, 3) / factorial(100)
  z +=  nCr(75,k) * subFactorial(97 - k) * nCr(25, 3) / factorial(100) 
 
#z = sum((-1.0)**k * nCr(22, k) * factorial(97 - k) for k in range(23)) * nCr(25, 3) / factorial(100)
 
print z

# for m in xrange(1,7):
  # print R(8,m)
  
# print R(25,22)
 
# print R(25,3)/factorial(25)
# print
# for i in xrange(25,101):
  # for j in xrange(3,79):
    # if j> i:continue
예제 #15
0
def R(n, k):
    return nCr(n, k) * subFactorial(n - k)
예제 #16
0
    return factorial(n) * summ


st = time()


def R(n, k):
    return nCr(n, k) * subFactorial(n - k)


z = 0.0

for k in xrange(23):
    #z +=  (-1.0)**k * nCr(22, k) * factorial(97 - k) * nCr(25, 3) / factorial(100)
    z += nCr(75, k) * subFactorial(97 - k) * nCr(25, 3) / factorial(100)

#z = sum((-1.0)**k * nCr(22, k) * factorial(97 - k) for k in range(23)) * nCr(25, 3) / factorial(100)

print z

# for m in xrange(1,7):
# print R(8,m)

# print R(25,22)

# print R(25,3)/factorial(25)
# print
# for i in xrange(25,101):
# for j in xrange(3,79):
# if j> i:continue