本文整理匯總了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);
}