CP Session
CP Session
#Rapid CP
Unlocking Competitive
Programming Secrets
behind Speedy Solutions
Date : 28-03-2024
Modulo Arithmetics
Modular arithmetic is a system of arithmetic for
integers, where numbers “wrap around” upon reaching
a certain value, known as the modulus.
Let us consider 2 ^ 12
Binary Exponentiation ,
2 ^ 12 = (2)^ 2 * 6 = (16) ^ 3
= (4) ^ 6 = 16 * (16) ^ 2
= (4) ^ 2 * 3 = 16 * (256) ^ 1
Binary Exponentiation
Methodology
So, the final time complexity is O(log n) :
To find a^b ,
Prime Check
Prime Number Definition :
Prime numbers are numbers that have only 2 factors: 1 and
themselves
Ex : 2, 5, 7 …
Motivation :
Given a number n, print all primes smaller
than or equal to n. It is also given that n is a small
number
Problem:
https://leetcode.com/problems/count-primes/
https://leetcode.com/problems/missing-number/
WHAT IS SUBSET ?
Subset vs SubArray
Bit Mask ?
Lets code …
Check it out :
https://www.geeksforgeeks.org/find-distinct-subsets-
given-set/
Links to ponder
● https://www.geeksforgeeks.org/modular-arithmetic-for-compe
titive-programming/
● https://cp-algorithms.com/algebra/binary-exp.html
● https://leetcode.com/problems/count-good-numbers/
● https://cp-algorithms.com/algebra/sieve-of-eratosthenes.html
● https://leetcode.com/problems/count-primes/
● https://leetcode.com/problems/four-divisors/
● https://www.geeksforgeeks.org/bits-manipulation-important-t
actics/
Join our Community