标签:bre isp prime else break pre bsp list() prim
1. 质因数分解
public static List<Integer> factorize(int n){ List<Integer> factors = new ArrayList(); int i; boolean isPrime = true; for (i = 2; i <= Math.sqrt(n); i++){ if (n % i == 0){ factors.add(i); isPrime = false; break; } } if (isPrime){ factors.add(n); }else{ factors.addAll(factorize( n / i)); } return factors; }
标签:bre isp prime else break pre bsp list() prim
原文地址:https://www.cnblogs.com/cloudwind2011/p/10961307.html