Prime Factors In C#

int a, b; Console.WriteLine(“Please enter your integer: “); a = int.Parse(Console.ReadLine()); for (b = 2; a > 1; b++) if (a % b == 0) { int x = 0; while (a % b == 0) { a /= b; x++; } Console.WriteLine($”{b} is a prime factor {x} times!”); } Console.WriteLine(“Th-Th-Th-Th-Th-… That’s all, folks!”);

Fast prime factorization module

If you don’t want to reinvent the wheel, use the library sympy pip install sympy Use the function sympy.ntheory.factorint Given a positive integer n, factorint(n) returns a dict containing the prime factors of n as keys and their respective multiplicities as values. For example: Example: >>> from sympy.ntheory import factorint >>> factorint(10**20+1) {73: 1, 5964848081: … Read more