# Formula For Summing A Sequence of Squares

Suppose you want to find the sum of the squares of all integers from 1 up to 200. Doing it manually would be boring a take a lot of time. Instead you can use the formula below: S = 1/6 * n * (n + 1) * (2n + 1) So in our case the […]

# How Many Different Pairs on a Tenis Tournament

Suppose you have 10 tenis players competing on your tournament, and you want to figure out in how many different pairs you can organize them so that they can play their first match. One way to calculate this is the following: First pick one player at random. Now to pick his opponent you have 9 […]

# Basics of Combinations

First make sure to read the basics of permutations. So what’s the different between permutations and combinations? Suppose we have set A = {a,b,c,d,e}. A permutation of that set could be abc, and another permutation could be acb. In other words, a permutation is an arrangement of the objects of set A, where order matters. […]

# Euclid’s Algorithm for Finding the GCD

The oldest known trivial algorithm known: int gdc (int x, int y){     int temp;     while (y!=0){         temp=y;         y=x%y;         x=temp;     }     return x; } Check the Wikipedia entry to read more about it.

# How To Find The Number of Divisors of a Number

Here’s a cool trick to find the number of divisors of any number easily. First of all find the prime factors of that number. Say we want to do it for 1000. 1000 = 2³ * 5³ Now we can say that all proper divisors of 1000 will be in the form of 2^a * […]

# Proving that 1/8 Is Larger Than 1/4

Yep, you’ve read that right. Here we go (log below means log10, so log with base 10): 3 > 2 3 log(1/2) > 2 log(1/2) log[(1/2)³] > log[(1/2)²] (1/2)³ > (1/2)² 1/8 > 1/4 Convinced? If not, what’s wrong with the proof above? Click to see solution In reality log10(1/2) is negative, so the second […]

# Basics of Permutations

In how many ways can you arrange a group of 4 items? Most people (well, programmers at least) know the answer for that is 24, which is 4!. But what about the more generic case where you have n items and want to permutate only k of them at a time, how many permutations are […]