The most beautiful experience we can have is the mysterious.

Sum Of Digits

Sum all the digits of number N (>0), if result has more than one digit, repeat summing all the digits of the result of each round, until reaching a single digit number R. For example: $$N = 365 => 3 + 6 + 5 = 14 => R = 1 + 4 = 5 $$ Algorithm: $$R = (N – 1) mod 9 + 1$$ Proof Represent each digit in N as a_{k}

Estimate Pi

Monte Carlo Method

Area of square: $$S_s = L*L$$ Area of circle: $$S_c = Pi*(L/2)2$$ Draw random dots, with sufficient dots, the probability of dots appearing in the circle approaximately equals the area of the circle within the area of the square: $$N_c ⁄ N_c ≈ S_c ⁄ S_s = (Pi*(L/2)2) ⁄ (L*L)$$ $$=> Pi = N_c ⁄ N_s *4 $$ Play the demo here Code in Github

Is 2021 A Prime Number?

A prime number is a positive integer that can only be exactly divided by itself and 1. Algorithm: to judge whether X is a prime number or not, we can assume a number n has n x n = X (n = sqrt(X)). If X is not prime, it will have at least one integer pair n1 and n2, such that n1 x n2 = X, n1∈[2,n], n2∈[n,X]. We can then narrow down the scope that if X is exactly divisible by a number between 2 and sqrt(X), it is not a prime; otherwise, it is a prime.

Show N^M As Sum Of Consecutive N Odd Numbers

(M,N>=2)

Split n^m into n numbers, the average of the numbers would be n^{m-1}. If n is odd, we can produce the consecutive odd numbers {…n^{m-1}-4, n^{m-1}-2, n^{m-1}, n^{m-1}+2, n^{m-1}+4…}. For example, for 3^3, it will be {7, 9, 11}. If n is even, we can produce the consecutive odd numbers {…n^{m-1}-5, n^{m-1}-3, n^{m-1}-1, n^{m-1}+1, n^{m-1}+3, n^{m-1}+5…}. For example, for 4^3, it will be {13, 15, 17, 19}. It can be written as: