本文整理汇总了Java中org.apache.commons.math3.primes.Primes类的典型用法代码示例。如果您正苦于以下问题:Java Primes类的具体用法?Java Primes怎么用?Java Primes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Primes类属于org.apache.commons.math3.primes包,在下文中一共展示了Primes类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: firstNPrimes
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
public static List<Integer> firstNPrimes(int count) {
LOGGER.debug("Calculating first {} primes", count);
List<Integer> primes = new ArrayList<>(count);
int prime = 2;
for (int i = 0; i < count; i++) {
primes.add(prime);
prime = Primes.nextPrime(prime + 1);
}
return primes;
}
示例2: 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;
}
}
示例3: setNumberOfReducers
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
protected void setNumberOfReducers(Job job) throws IOException {
long inputSize = getInputSize();
long targetFileSize = getTargetFileSize();
int numReducers = Math.min(Ints.checkedCast(inputSize / targetFileSize) + 1, getMaxNumReducers());
if (this.usePrimeReducers && numReducers != 1) {
numReducers = Primes.nextPrime(numReducers);
}
job.setNumReduceTasks(numReducers);
}
示例4: setNumberOfReducers
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
/**
* Refer to {@link MRCompactorAvroKeyDedupJobRunner#setNumberOfReducers(Job)}
*/
protected void setNumberOfReducers(Job job) throws IOException {
// get input size
long inputSize = 0;
for (Path inputPath : this.mapReduceInputPaths) {
inputSize += this.fs.getContentSummary(inputPath).getLength();
}
// get target file size
long targetFileSize = this.state.getPropAsLong(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_TARGET_OUTPUT_FILE_SIZE,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_TARGET_OUTPUT_FILE_SIZE);
// get max reducers
int maxNumReducers = state.getPropAsInt(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_MAX_NUM_REDUCERS,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_MAX_NUM_REDUCERS);
int numReducers = Math.min(Ints.checkedCast(inputSize / targetFileSize) + 1, maxNumReducers);
// get use prime reducers
boolean usePrimeReducers = state.getPropAsBoolean(MRCompactorAvroKeyDedupJobRunner.COMPACTION_JOB_USE_PRIME_REDUCERS,
MRCompactorAvroKeyDedupJobRunner.DEFAULT_COMPACTION_JOB_USE_PRIME_REDUCERS);
if (usePrimeReducers && numReducers != 1) {
numReducers = Primes.nextPrime(numReducers);
}
job.setNumReduceTasks(numReducers);
}
示例5: nextTwinPrime
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
/**
* Finds next-largest "twin primes": numbers p and p+2 such that both are prime. Finds the smallest such p
* such that the smaller twin, p, is greater than or equal to n. Returns p+2, the larger of the two twins.
*/
public static int nextTwinPrime(int n) {
if (n > MAX_INT_SMALLER_TWIN_PRIME) {
throw new IllegalArgumentException();
}
if (n <= 3) {
return 5;
}
int next = Primes.nextPrime(n);
while (!Primes.isPrime(next + 2)) {
next = Primes.nextPrime(next + 4);
}
return next + 2;
}
示例6: update
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
public void update()
{
seed.set(Primes.nextPrime(seed.get() + 1));
random.setSeed(seed.get());
}
示例7: getFactors
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
public List<Integer> getFactors(Integer number) {
return Primes.primeFactors(number);
}
示例8: determine_if_number_prime_with_apache_commons
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
@Test
public void determine_if_number_prime_with_apache_commons () {
boolean isPrimeNumber = Primes.isPrime(5779);
assertTrue(isPrimeNumber);
}
示例9: find_next_prime_number_with_apache_commons
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
@Test
public void find_next_prime_number_with_apache_commons () {
int nextPrimeNumber = Primes.nextPrime(5780);
assertEquals(5783, nextPrimeNumber);
}
示例10: 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));
}
示例11: isPrime
import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
/**
* The isPrime method determines whether a number is prime.
*
* {@link Primes} is a utility method found in apache commons.
* In this instance I am wrapping this method but isn't necessary.
*
* @param num
* The number to check.
* @return true if the number is prime, false otherwise.
*/
public static boolean isPrime(int number) {
return Primes.isPrime(number);
}