Carmichael NumbersA number n is said to be a Carmichael number if it satisfies the following modular arithmetic condition: power(b, n-1) MOD n = 1, for all b ranging from 1 to n such that b and n are relatively prime, i.e, gcd(b, n) = 1 Given a positive integer n, find if it is a Carmichael number. These numbers have
8 min read
Number Theory | Generators of finite cyclic group under additionGiven a number n, find all generators of cyclic additive group under modulo n. Generator of a set {0, 1, ... n-1} is an element x such that x is smaller than n, and using x (and addition operation), we can generate all elements of the set.Examples: Input : 10 Output : 1 3 7 9 The set to be generated
5 min read
GFact | 2x + 1(where x > 0) is prime if and only if x is a power of 2A number of the form 2x + 1 (where x > 0) is prime if and only if x is a power of 2, i.e., x = 2n. So overall number becomes 22n + 1. Such numbers are called Fermat Number (Numbers of form 22n + 1). The first few Fermat numbers are 3, 5, 17, 257, 65537, 4294967297, .... An important thing to note
1 min read
Sieve of EratosthenesGiven a number n, find all prime numbers less than or equal to n.Examples:Input: n = 10Output: [2, 3, 5, 7]Explanation: The prime numbers up to 10 obtained by Sieve of Eratosthenes are [2, 3, 5, 7].Input: n = 35Output: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]Explanation: The prime numbers up to 35 o
5 min read