For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.
Now, take the number 20, and it is a composite number. So, split the number 20 into its prime factors. Here, 5 is a prime number and 4 is a composite number, which can be factored further. Hence, the prime factorization of 20 is 2 × 2 × 5 or 22 × 5.
Prime Factorization DefinitionThe method of breaking down a number into its prime numbers that help in forming the number when multiplied is called prime factorization. In other words, when prime numbers are multiplied to obtain the original number, it is defined as the prime factorization of the number.
C#, 69
x is input number
int i=2;while(x>1)if(x%i++==0){x/=--i;Console.Write(i+(x>1?"x":""));};
With includes:
using system;
namespace nameSP
{
class Program
{
static void Main(string[] args)
{
int i=2;while(x>1)if(x%i++==0){x/=--i;Console.Write(i+(x>1?"x":""));};
}
}
}
Obligatory J answer (2 characters):
q:
ANSI C, 79 characters
main(d,i){for(d+=scanf("%d",&i);i>1;i%d?++d:printf("%d%c",d,(i/=d)>1?'x':10));}
Mathematica (15 chars including brackets):
FactorInteger
Example:
FactorInteger[42]
{{2, 1}, {3, 1}, {7, 1}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With