🔆

Warm-up to Number theory !

 
Here are some basic math formulas and identities that are commonly used in competitive programming:
 
  1. Arithmetic Progression (AP) formula:
      • Sum of n terms of AP: S = n/2(2a + (n-1)d)
      • nth term of AP: an = a1 + (n-1)d
  1. Geometric Progression (GP) formula:
      • Sum of n terms of GP: S = a(1-r^n)/(1-r)
      • nth term of GP: an = ar^(n-1)
  1. Pythagorean theorem: a^2 + b^2 = c^2 (where c is the hypotenuse of a right triangle, and a and b are the other two sides)
  1. Quadratic formula: x = (-b + sqrt(b^2 - 4ac)) / 2a and x = (-b - sqrt(b^2 - 4ac)) / 2a (where a, b, and c are coefficients of a quadratic equation)
  1. Euler's formula: e^(i*pi) + 1 = 0 (where e is the base of the natural logarithm, i is the imaginary unit, and pi is the ratio of a circle's circumference to its diameter)
  1. Factorial formula: n! = n * (n-1) * (n-2) * ... * 2 * 1
  1. Permutation formula: nPr = n!/(n-r)! (where n and r are integers, and r is less than or equal to n)
  1. Combination formula: nCr = n!/((n-r)! * r!) (where n and r are integers, and r is less than or equal to n)
  1. Binomial theorem: (a+b)^n = a^n + nCa^(n-1)b + nC2a^(n-2)b^2 + ... + nb^n (where a and b are constants, and n is a positive integer)
  1. The sum of the first n natural numbers can be calculated using the following formula:
sum = n*(n+1)/2
where n is the number of natural numbers to be added.
For example, if we want to find the sum of the first 10 natural numbers, we can substitute n = 10 in the formula:
sum = 10*(10+1)/2 = 55
Therefore, the sum of the first 10 natural numbers is 55.