Carmichael function

Problem Source: Codewars In number theory, the Carmichael function of a positive integer $n$, denoted $\lambda(n)$, is defined as the smallest positive integer m such that $$a^m \equiv 1 \mod n$$ for every integer $a \leq n$ that is coprime to $n$. The Carmichael function is also known as the reduced totient function (as it is linked to Euler Totient function) or the least universal exponent function. The Carmichael function is important in number theory....

September 4, 2021

Sum of intervals

Problem Source: Codewars Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only be counted once. Intervals Intervals are represented by a pair of integers in the form of an array. The first value of the interval will always be less than the second value. Interval example: [1, 5] is an interval from 1 to 5. The length of this interval is 4....

July 27, 2021

Primes in numbers

Problem Codewars Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form: ($p_1$**$n_1$)($p_2$**$n_2$)…($p_k$**$n_k$) where a**b means $a^b$ $p_i$ in increasing order $n_i$ empty if n(i) is 1. Example: Input: n = 86240 Output: (2**5)(5)(7**2)(11) Solution Generally, in order to calculate all of the prime factors of a number, you have to go about dividing the original number by its smallest prime factor....

January 23, 2021