当前位置: 首页>>代码示例>>Java>>正文


Java Primes类代码示例

本文整理汇总了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;
}
 
开发者ID:wipu,项目名称:iwant-demo,代码行数:11,代码来源:Mathlib.java

示例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;
    }
}
 
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:32,代码来源:BuildValue.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:10,代码来源:MRCompactorJobRunner.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:31,代码来源:CompactionAvroJobConfigurator.java

示例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;
}
 
开发者ID:apsaltis,项目名称:oryx,代码行数:18,代码来源:RandomUtils.java

示例6: update

import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
public void update()
{
    seed.set(Primes.nextPrime(seed.get() + 1));

    random.setSeed(seed.get());
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:7,代码来源:RandomHelper.java

示例7: getFactors

import org.apache.commons.math3.primes.Primes; //导入依赖的package包/类
public List<Integer> getFactors(Integer number) {
    return Primes.primeFactors(number);
}
 
开发者ID:ahoffer,项目名称:osgi,代码行数:4,代码来源:Factorizer.java

示例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);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:7,代码来源:NumberIsPrime.java

示例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);
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:8,代码来源:NumberIsPrime.java

示例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));
}
 
开发者ID:wq19880601,项目名称:java-util-examples,代码行数:8,代码来源:NumberIsPrime.java

示例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);
}
 
开发者ID:leveluplunch,项目名称:levelup-java-exercises,代码行数:14,代码来源:NumberIsPrime.java


注:本文中的org.apache.commons.math3.primes.Primes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。