user-0 提问: 用C语言实现，将100以内的自然数分解质因数

回复:
user: user-1
content: void  AnalyFactor(int n,list<int> &nList) { 	if(!nList.empty()) 	{ 		nList.clear(); 	} 	for(int i=2;i<=n;i++) 	{ 		while(n!=i) 		{ 			if(n%i==0) 			{ 				nList.push_back(i); 				n=n/i; 			} 			else 				break; 		} 	} 	nList.push_back(n); }

user: user-2
content: 最高速的方法：查表（穷举表） 最简单的方法：判断%余数

user: user-3
content: 仅供参考，尽管是C# //****************************************************************************** // Author           :   Alexander Bell // Copyright        :   2007-2011 Infosoft International Inc // Date Created     :   01/15/2007 // Last Modified    :   02/08/2011 // Description      :   Prime Factoring //****************************************************************************** // DISCLAIMER: This Application is provide on AS IS basis without any warranty //****************************************************************************** //****************************************************************************** // TERMS OF USE     :   This module is copyrighted. //                  :   You can use it at your sole risk provided that you keep //                  :   the original copyright note. //****************************************************************************** using System; using System.Collections.Generic; namespace Infosoft.MathShared {     /// <summary>Integers: Properties and Operations</summary>      public  static partial class Integers     {         #region Prime Numbers <100         private static readonly int[] Primes =         new int[] { 2, 3, 5, 7, 11, 13, 17, 19, 23,                     29, 31, 37, 41, 43, 47, 53, 59,                     61, 67, 71, 73, 79, 83, 89, 97 };         #endregion          // starting number for iterative factorization         private const int _startNum = 101;         #region IsPrime: primality Check         /// <summary>         /// Check if the number is Prime         /// </summary>         /// <param name="Num">Int64</param>         /// <returns>bool</returns>         public static bool IsPrime(Int64 Num){             int j;             bool ret;             Int64 _upMargin = (Int64)Math.Sqrt(Num) + 1; ;             // Check if number is in Prime Array             for (int i = 0; i < Primes.Length; i++){                 if (Num == Primes[i]) { return true; }             }             // Check divisibility w/Prime Array             for (int i = 0; i < Primes.Length; i++) {                 if (Num % Primes[i] == 0) return false;             }             // Main iteration for Primality check             _upMargin = (Int64)Math.Sqrt(Num) + 1;             j = _startNum;             ret = true;             while (j <= _upMargin)             {                 if (Num % j == 0) { ret = false; break; }                 else { j++; j++; }             }             return ret;         }         /// <summary>         /// Check if number-string is Prime         /// </summary>         /// <param name="Num">string</param>         /// <returns>bool</returns>         public static bool IsPrime(string StringNum) {             return IsPrime(Int64.Parse(StringNum));         }         #endregion         #region Fast Factorization         /// <summary>         /// Factorize string converted to long integers         /// </summary>         /// <param name="StringNum">string</param>         /// <returns>Int64[]</returns>         public static Int64[] FactorizeFast(string StringNum) {             return FactorizeFast(Int64.Parse(StringNum));         }         /// <summary>         /// Factorize long integers: speed optimized         /// </summary>         /// <param name="Num">Int64</param>         /// <returns>Int64[]</returns>         public static Int64[] FactorizeFast(Int64 Num)         {             #region vars             // list of Factors             List<Int64> _arrFactors = new List<Int64>();             // temp variable             Int64 _num = Num;             #endregion             #region Check if the number is Prime (<100)             for (int k = 0; k < Primes.Length; k++)             {                 if (_num == Primes[k])                 {                     _arrFactors.Add(Primes[k]);                     return _arrFactors.ToArray();                 }             }             #endregion             #region Try to factorize using Primes Array             for (int k = 0; k < Primes.Length; k++)             {                 int m = Primes[k];                 if (_num < m) break;                 while (_num % m == 0)                 {                     _arrFactors.Add(m);                     _num = (Int64)_num / m;                 }             }             if (_num < _startNum)             {                 _arrFactors.Sort();                 return _arrFactors.ToArray();             }             #endregion             #region Main Factorization Algorithm             Int64 _upMargin = (Int64)Math.Sqrt(_num) + 1;             Int64 i = _startNum;             while (i <= _upMargin)             {                 if (_num % i == 0)                 {                     _arrFactors.Add(i);                     _num = _num / i;                     _upMargin = (Int64)Math.Sqrt(_num) + 1;                     i = _startNum;                 }                 else { i++; i++; }             }             _arrFactors.Add(_num);             _arrFactors.Sort();             return _arrFactors.ToArray();             #endregion         }         #endregion     } } //******************************************************************************

user: user-4
content: 引用 5 楼 syrchina 的回复:最高速的方法：查表（穷举表） 最简单的方法：判断%余数查表好

user: user-3
content: Finding prime numbers - Kenneth Haugland Different schemas for finding prime numbers explained with code http://www.codeproject.com/Article.aspx?tag=198374988322054872&

user: user-5
content: 任意输入一个整数，将这个整数进行质因数分解n(2<=n<=100000000)；

user: user-5
content: #include<stdio.h> #include<math.h> int fenjie(int n) { 	for(int i=2;i<=sqrt(n);i++) 	{ 		if(n%i==0) 		{ 			printf("%d*",i); 			return fenjie(n/=i); 			break; 		} 	} 	return printf("%d\n",n); } int main() { 	int num; 	while(scanf("%d",&num)!=EOF) 		fenjie(num); 	return 0; }