javascript实现: /******************** 质因子分解算法 by cutbug 2009-2-12 *********************/ function getPreGens(a) { var arr = []; var n = Math.floor(a/2)+ 1; var t = n; var i; while(1==1) { if(i==t) { arr.push(a); break; } for(i=2; i<t; i++) { if(a%i == 0) { arr.push(i); a = a/i; t = Math.floor(a/2 )+ 1; break; } } } return arr; } alert(getPreGens(19900));//2,2,5,5,199 C#实现 private List<int> GetPrimGen(int a) { List<int> iList = new List<int>(); int n = Convert.ToInt32(Math.Floor(Convert.ToDecimal(a)/2))+ 1; int t = n; int i = 0; while(1==1) { if(i==t) { iList.Add(a); break; } for(i=2; i<t; i++) { if(a%i == 0) { iList.Add(i); a = a/i; t = Convert.ToInt32(Math.Floor(Convert.ToDecimal(a) / 2)) + 1; break; } } } return iList; }