def binomial(x1, x2, n, p): q = 1 - p b = 0 for x in range(x1, x2 + 1): b += (ft(n) / (ft(x) * ft(n - x))) * p**x * q**(n - x) return round(b, 3)
def sqrt(self, N): s = 0.0 for i in range(1, N): a = (-1) ** i * ft(2 * i) b = (1 - 2 * i) * ft(i) ** 2 * 4 ** i c = a / b #print(a, b, s) s += c * self.zeta ** i return MyNumber(s)
def calc(ball, drawn): """ :param ball: vaihtoehtojen määrä :param drawn: suotuisat tapaukset :return: laskee todennäköisyyden ja näyttää sen ulostuloon """ prob = int((ft(ball) / (ft(drawn) * ft(ball - drawn)))) return print( f"The probability of guessing all {drawn} balls correctly is 1/{prob}")
def probabilityOfAaBb(k, n): ## no. of organisms # what we have to do # find out the probability of atleast N org will belong to the k-th generation # simple binomial probability P = 2**k p = 0.25 q = 1 - p proba = 0 for i in range(n, P + 1): probability = (ft(P) / (ft(i) * ft(P - i))) * (p**i) * (q**(P - i)) print(probability) proba += probability return print("/probabilit:", round(proba, 3))
def rank(s): st = list(s) rank = 1 n = len(st) for i in range(n): r = rep(st[i:]) rank += (least(st[i:],st[i])*ft(n-i-1))//r return rank
def main(): S = input().strip() d = {'o': 0, 'x': 0, '?': 0} for c in S: if c in d: d[c] += 1 else: d[c] = 1 if d['o'] >= 5: print(0) elif d['o'] == 4: print(ft(4)) elif d['o'] == 3: print(ft(4) // 2 * 3 + ft(3) * d['?'] * 4) elif d['o'] == 2: print(14 + 6 * d['?'] * 4 + 2 * d['?']**2 * 6) elif d['o'] == 1: print(1 + d['?'] * 4 + d['?']**2 * 6 + d['?']**3 * 4) else: print(d['?']**4)
def binomial(x, n, p): q = 1 - p b = 0 for i in range(x, n + 1): b = b + (ft(n) / (ft(i) * ft(n - i))) * p**i * q**(n - i) return round(b, 3)
import platform x = platform plataforma = x.system() print(plataforma) print(x.processor) print(x.python_version()) # Utilizar nossos proprios modulos '''import meu_modulo meu_modulo.boas_vindas('Marcelo')''' # Carregando determinada rotina de um modulo from math import factorial # se usarmos o * importa tudo tbm ex: "from math import *" numero = 6 print('O fatorial de {} é {}'.format(numero, factorial(numero))) # Modulos com apelidos from math import factorial as ft numero = 5 print('O fatorial de {} é {}'.format(numero, ft(numero)))
from math import factorial as ft for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) c0 = a.count(0) c1 = a.count(1) c2 = a.count(2) su = 0 if c0 > 1: su = su + (ft(c0) / (ft(c0 - 2) * ft(2))) if c1 > 1: su = su + (ft(c1) / (ft(c1 - 2) * ft(2))) if c2 > 1: su = su + (ft(c2) / (ft(c2 - 2) * ft(2))) print(int(su))
from math import factorial as ft for __ in range(int(input())): k = int(input()) for i in range(k + 1): num = ft(k) / (ft(k - i) * ft(i)) print(int(num), end=" ")
if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while (i * i <= n): if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True n = input() if n.isdigit() and int(n) > 0: n = int(n) n = ft(n) l = list() for i in range(2, 10000): if isprime(i): l.append(i) te = 0 ans = "" cnt = 0 while n != 1: if n % l[te] == 0: cnt += 1 n = n // l[te] else: ans += str(cnt) + " " cnt = 0 te += 1
def c(n, r): return float(ft(n)) / (ft(r) * ft(n - r))
In this doc, we will explore the Python Standard Library. Generally, a module contains functions related to a particular aspect of programming. This makes things easy because we know which part of our program requires which module. """ import datetime import random from math import factorial as ft, log from heapq import heappush as push, heappop as pop print(datetime.date.today()) print(datetime.datetime.now()) print(datetime.datetime.now().strftime('%m/%d/%Y, %H:%M:%S')) print(datetime.datetime.now().strftime('%Y')) # will print year print(ft(4)) print(log(10)) """ The heapq module allows us to create the heap data structure. A heap is a binary tree which always stores a special value at the top (root). A minheap stores the smallest value at the top and a maxheap stores the largest value at the top. """ heap = [] push(heap, 74) push(heap, 10) push(heap, 5) push(heap, 12.001) print(heap)
def rep(n): s = set(n) res = 1 for i in s: res = res * ft(n.count(i)) return res
def poisson(k, l): return round((l**k * exp(-l))/ft(k),3)
def solution(n, m): answer = int(ft(n + m) / ft(n) / ft(m)) return answer