Factorial decomposition

Problem Source: Codewars The aim of the kata is to decompose $n!$(factorial n) into its prime factors. For example: Input: n = 12 Output: 2^10 * 3^5 * 5^2 * 7 * 11 Note that $n$ can reach 4000 and, of course, 4000! would be very big with more than 12000 digits ∑(O_O;) Solution Idea By definition, the factorial of a positive integer $n$, denoted by $n!$, is the product of all positive integers less than or equal to $n$: $$12!...

January 26, 2021

T-Primes

Promblem Source: Codeforces We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we’ll call a positive integer $t$ Т-prime, if $t$ has exactly three distinct positive divisors. You are given an array of $n$ positive integers. For each of them determine whether it is Т-prime or not. Examples Input: 3 4 5 6 Output: YES NO NO Solution First, we need to find all prime numbers from 2 to $\sqrt{x}$....

January 22, 2021

Sum by Factors

The problem: Source: codewars Given an array of positive or negative integers $I = [i_1, .., i_n]$ , you have to produce a sorted array P of the form [ [$p$, sum of all $i_j$ of $I$ for which $p$ is a prime factor ($p$ positive) of $i_j$] …] P will be sorted by increasing order of the prime numbers. The final result has to be given as a string in Java, C#, C, C++ and as an array of arrays in other languages....

January 18, 2021