Competitive programming beginner topics part 2

4— layout: post title: “Competitive Programming Beginner Topics Part 2” tags: [Writing, competitive programming,Competitive Programming Beginner] usemathjax: true —

Primal proficiency

1. Basic math

Problems


2. Primality, Factorization and Sieve of Eratosthenes

Efficient factorization and prime checking is a must know when it comes to competitive programming. This is the place to start for number theory.

Reading material:

Problems

3. Euclidean GCD and Euler’s Totient function

You’ll see a fair number of easy mathy problems whose solutions involve finding and using the Greatest Common Divisor (GCD) of some numbers. The Euler totient function is rarer, but it is still good to know.

Reading material:

Problems


Challenging problems


Tip: Use std::gcd or __gcd() (a builtin function of the GCC compiler).

4. Modular Arithmetic

Have you ever seen something like find the answer modulo 109+7? If you’re still wondering what it means (or even if you’re not), you should read up on Modular arithmetic.

Reading material:

Try this problem.

My solution in C++

Modint template solution in C++

See snippet for implementation.

4. Binary Exponentiation

Binary exponentiation (also known as exponentiation by squaring) is a trick which allows you to calculate $a^n$ using only $\mathcal{O}(logn)$ multiplications (instead of $\mathcal{O}(n)$ multiplications).

Of course, this also works under mod. This is sometimes referred to as Modular Exponentiation.

Reading material:

Problems

Practice

Mashups of topic relevant problems spanning a range of difficulties.

Mashup 1
Mashup 2

Competitive Programming Beginner Topics Part 3