function solve(r1, r2) {
if (r2 === undefined) {
// add a line that connects 2r and 2R
// intersecting chrods: t/2 * t/2 and 2r * 2R
// t^2 / 4 = 4rR
// rR = t^2 / 16
return 2 * Math.PI * r1**2 / 16;
}
// PI(r^2 + R^2 + 2rR - r^2 - R^2) = PI * 2rR
/*
if m % n === 0, return m
when n prime number:
make (m-n+1) pieces of 1/m
other pieces is (n-1) grouped like (a, b):
1/a = 1/mn
1/b = (m-1)/mn
function solve(N, A, B, C) {
/*
s1 - step + 1
s2 - step + 2
s3 - step + 3
[0, Infinity, Infinity] - init values for steps
when reduce end, first array number will be answer
*/
return A.reduce(([s1, s2, s3], _, i) => [
import math
def solve(N, A, B, C):
seq: list = [math.inf] * N
for i in range(N):
prev: number = 0 if i == 0 else seq[i-1]
seq[i] = min(seq[i], prev + A[i])
if i + 1 < N:
seq[i+1] = min(seq[i+1], prev + B[i])
function solve(N, A, B, C) {
let min = Infinity;
const steps = {};
const findPaths = (sum, index) => {
if (steps[index] === undefined) {
steps[index] = sum;
} else {
if (sum >= steps[index]) { // if better path already exist, cancel next recursion
function solve(m, n, a, b, occupied) {
// all possible squares
let total = (m - a + 1) * (n - b + 1);
// init array[m][n] with all unchecked items
const checked = Array.from({length: m}, _ => Array.from({length: n}, __ => false));
occupied.forEach(([x, y]) => {
// array begin from zero
x = x - 1;
function solve(n, m) {
// when m = 1, every employee have single key
if (m === 1) {
return 1;
}
// when m = 2 every employee have (n - 1) key
// when m = n, every employee have 1 key
if (m === 2 || m === n) {
return n;
CNK_MAX_VALUE = 2**64
K_N_MAX_VALUE = 2**32
def binom(n, k):
if n > K_N_MAX_VALUE or k > K_N_MAX_VALUE:
raise Exception('n or k more than max value')
greater = n - k if n - k > k else k
cnk = 1
# from greater to n, larger factorial shrinks
const solve = (function() {
// init values
const memory = {1: 1, 2: 2, 3: 4};
return function count(n) {
if (memory[n]) {
return memory[n];
}
/*
total possible positions is 2^n
function solve(width, height) {
const [big, small] = width > height ? [width, height] : [height, width];
// largest possible side of square is small part
// ***** => *
if (big >= small * 3) {
return small;
}
// if it can't use small part as side, try to use big/3 part, it make sense when small*2 <= big < small*3
// ******