本文整理汇总了Java中com.jwetherell.algorithms.mathematics.Primes类的典型用法代码示例。如果您正苦于以下问题:Java Primes类的具体用法?Java Primes怎么用?Java Primes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Primes类属于com.jwetherell.algorithms.mathematics包,在下文中一共展示了Primes类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrimeFactorization
import com.jwetherell.algorithms.mathematics.Primes; //导入依赖的package包/类
@Test
public void getPrimeFactorization() {
int number = 234;
Map<Long,Long> factorization = Primes.getPrimeFactorization(number);
Map<Long,Long> check = new HashMap<Long,Long>();
{
check.put(2l, 1L);
check.put(3l, 2L);
check.put(13L, 1L);
}
for (Long k : factorization.keySet()) {
Long f = factorization.get(k);
Long c = check.get(k);
assertTrue("PrimeFactorization error. expected="+c+" got="+f, (c==f));
}
}
示例2: sieveOfEratosthenes
import com.jwetherell.algorithms.mathematics.Primes; //导入依赖的package包/类
@Test
public void sieveOfEratosthenes() {
int number = 4177;
boolean isPrime = Primes.sieveOfEratosthenes(number);
assertTrue("Sieve Of Eratosthenes error.", isPrime);
number = 4178;
isPrime = Primes.sieveOfEratosthenes(number);
assertFalse("Sieve Of Eratosthenes error.", isPrime);
number = 7919;
isPrime = Primes.sieveOfEratosthenes(number);
assertTrue("Sieve Of Eratosthenes error.", isPrime);
number = 556;
isPrime = Primes.sieveOfEratosthenes(number);
assertFalse("Sieve Of Eratosthenes error.", isPrime);
number = 6091;
isPrime = Primes.sieveOfEratosthenes(number);
assertTrue("Sieve Of Eratosthenes error.", isPrime);
number = 6090;
isPrime = Primes.sieveOfEratosthenes(number);
assertFalse("Sieve Of Eratosthenes error.", isPrime);
number = 6089;
isPrime = Primes.sieveOfEratosthenes(number);
assertTrue("Sieve Of Eratosthenes error.", isPrime);
}