質數,質因數 應該都瞭解,在這裡不過多解釋,直接上代碼: ...
質數,質因數 應該都瞭解,在這裡不過多解釋,直接上代碼:
List<int> results = new List<int>(); int number = Int32.Parse(Console.ReadLine()); for (int pri = 2; pri < number; pri++) { while (number % pri == 0 && pri != number) { results.Add(pri); number /= pri; } } results.Add(number); foreach (var result in results) { Console.WriteLine(result); } Console.ReadKey();