Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace _01.Prime_Factorization
- {
- class Program
- {
- static void Main()
- {
- int n;
- while (true)
- {
- n = int.Parse(Console.ReadLine());
- if (n >= 2) break;
- }
- Console.Write("{0} = ", n);
- Console.WriteLine(FindPrimes(n));
- }
- private static string FindPrimes(int n)
- {
- List<int> primes = new List<int>();
- int counter = 2;
- do
- {
- if (n % counter == 0)
- {
- primes.Add(counter);
- n /= counter;
- continue;
- }
- counter++;
- }
- while (n != 1);
- return string.Join(" * ", primes);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment