Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Prime_Factorization
- {
- class Program
- {
- static void Main(string[] args)
- {
- int Prime = 1;
- double doublePrime = 0;
- int TimesDividingPrimes = 0;
- bool CheckPrime = true;
- int PrimeDivide = 1;
- bool StopLoop1 = false;
- int PowerCount = 0;
- int WhileUserNumber = 0;
- bool StopAll = false;
- Console.WriteLine("Enter the number you would like to see factorized");
- string UserNumber = Console.ReadLine();
- WhileUserNumber = int.Parse(UserNumber);
- while (StopAll == false)
- {
- ++Prime;
- doublePrime = Math.Sqrt(Prime);
- TimesDividingPrimes = (int)doublePrime;
- for (int PrimeLoop2 = 1; PrimeLoop2 < TimesDividingPrimes; ++PrimeLoop2)
- {
- ++PrimeDivide;
- if (Prime % PrimeDivide == 0 && Prime != 2)
- {
- CheckPrime = false;
- }
- if (CheckPrime == false)
- {
- PrimeLoop2 = TimesDividingPrimes;
- }
- }
- PrimeDivide = 1;
- if (CheckPrime == true)
- {
- while (StopLoop1 == false)
- {
- if (WhileUserNumber % Prime == 0 && WhileUserNumber != 1)
- {
- ++PowerCount;
- WhileUserNumber = (WhileUserNumber / Prime);
- }
- else
- {
- StopLoop1 = true;
- }
- if (WhileUserNumber == 1)
- {
- StopLoop1 = true;
- StopAll = true;
- }
- }
- if (PowerCount == 1)
- {
- Console.WriteLine(Prime);
- }
- else if (PowerCount > 1)
- {
- Console.WriteLine(Prime + "^" + PowerCount);
- }
- PowerCount = 0;
- }
- CheckPrime = true;
- StopLoop1 = false;
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement