本文整理汇总了Java中org.apache.commons.math3.primes.Primes.primeFactors方法的典型用法代码示例。如果您正苦于以下问题:Java Primes.primeFactors方法的具体用法?Java Primes.primeFactors怎么用?Java Primes.primeFactors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.primes.Primes
的用法示例。
在下文中一共展示了Primes.primeFactors方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: build
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
public ObjectCreation build(int integer) {
if(valuesToObject.containsKey(integer)) {
return randomPick(valuesToObject.get(integer));
}
if(Primes.isPrime(integer)) {
ObjectCreation minus = new ArithmeticObject(randomPick(valuesToObject.get(1)), build(integer - 1), "minus");
addValue(integer, minus);
return minus;
} else {
ObjectCreation result = null;
int rest = integer;
for(Integer factor : Primes.primeFactors(integer)) {
int pow = 0;
while((rest/factor) * factor == rest) {
pow++;
rest = rest/factor;
}
ObjectCreation object = new ArithmeticObject(randomPick(valuesToObject.get(1)), build(pow), "pow");
addValue((int)Math.pow(factor, pow), object);
if(result == null) {
result = object;
} else {
ObjectCreation plus = new ArithmeticObject(result, object, "multi");
result = plus;
addValue((Integer) plus.getValue() + (Integer) result.getValue(), plus);
}
}
return result;
}
}
示例2: getFactors
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
public List<Integer> getFactors(Integer number) {
return Primes.primeFactors(number);
}
示例3: determine_prime_factors_of_a_number_with_apache_commons
import org.apache.commons.math3.primes.Primes; //导入方法依赖的package包/类
@Test
public void determine_prime_factors_of_a_number_with_apache_commons () {
List<Integer> primeFactors = Primes.primeFactors(5782);
assertThat(primeFactors, hasItems(2, 7, 7, 59));
}