primefactors: Primes, Prime Factorization, Common Divisor

View source: R/primefactors.R

primefactorsR Documentation

Primes, Prime Factorization, Common Divisor

Description

These functions find prime numbers, factorise a composite number into its prime factors, determine whether a number is prime, and find the least common multiple or greatest common divisor of two numbers.

Usage

primefactors(n, method=c("C", "interpreted"))
divisors(n)
is.prime(n)
relatively.prime(n, m)
least.common.multiple(n,m)
greatest.common.divisor(n,m)
primesbelow(nmax)

Arguments

n,m

Integers to be factorized.

nmax

Integer. Upper limit on prime numbers to be found.

method

Character string indicating the choice of algorithm. (Developer use only.)

Details

is.prime(n) returns TRUE if n is a prime number, and FALSE otherwise.

primefactors(n) factorises the integer n into its prime number factors, and returns an integer vector containing these factors. Some factors may be repeated.

divisors(n) finds all the integers which divide the integer n, and returns them as a sorted vector of integers (beginning with 1 and ending with n).

relatively.prime(n, m) returns TRUE if the integers n and m are relatively prime, that is, if they have no common factors.

least.common.multiple and greatest.common.divisor return the least common multiple or greatest common divisor of two integers n and m.

primesbelow(nmax) returns an integer vector containing all the prime numbers less than or equal to nmax.

Value

is.prime and relatively.prime return a logical value.

least.common.multiple and greatest.common.divisor return a single integer.

primefactors and primesbelow return an integer vector.

Author(s)

\adrian

.

Examples

  is.prime(17)

  relatively.prime(2, 3)
  
  primefactors(24) ## Note repeated factors

  divisors(24)

  greatest.common.divisor(60, 100) 

  least.common.multiple(10, 15) 

  primesbelow(20)

spatstat/spatstat.utils documentation built on Oct. 25, 2023, 10:07 p.m.