Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class PrimeFactorization
- {
- public static void Main()
- {
- int numberToFactorize = int.Parse(Console.ReadLine());
- Console.Write("{0} = ", numberToFactorize);
- int primeMultiple = 1;
- List<int> primeFactors = new List<int>();
- while (numberToFactorize != 1)
- {
- primeMultiple++;
- while (numberToFactorize % primeMultiple == 0)
- {
- primeFactors.Add(primeMultiple);
- numberToFactorize /= primeMultiple;
- }
- }
- Console.WriteLine(string.Join(" * ", primeFactors));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement