-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.cpp
More file actions
53 lines (38 loc) · 1.11 KB
/
math.cpp
File metadata and controls
53 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
// Finding number of digits in a number
// 123 = 3
// ans = floor(log10(n)+1);
// AP -> Arithmetic Progrssion
// 2 4 6 8 10 12 ...
// ans = n/2 * (2a+(n-1)d);
// a = first term
// d = common difference
// n = no of terms
// GP -> Geometric Progression
// 2 4 8 16 32 ...
// a ar^1 ar^2
// r = 2nd term / 1st term
// ans = a * (1 - r^n-1) / 1 - r
// Quadratic equations
// d = discriminant
// d = b^2 - 4 * a * c
// if d < 0 we have imaginary roots
// if d == 0 we have 2 equal roots
// if d > 0 we have 2 distinct roots
// x = roots of equation
// x = -b +- sqrt(b^2 - 4*a*c) / 2*a
// Median
// sort range and pick middle number
// 4 1 7 -> 1 4 7 || ans = 4
// if 2 mid values then mean of 2 numbers
// Prime numbers
// no's divided by itself and 1
// Prime no can be represented in form (6*n + 1 || 6*n - 1) except 2 and 3
// eg = 5 -> 6*1 - 1
// Permutation
// arrangements of r things that can be done out of n things
// nPr = fact(n) / fact(n-r)
// Combinations
// selection of r things that can be done out of r things
// nCr = fact(n) / fact(r) * fact(n - r)