Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

factorN

Create primes, factor an integer, combine factors, check if prime


Description

Create primes, determine the prime factors of an integer (first row) together with their multiplicities (second row), recombine factors, primitive version of the sieve of Eratosthenes.

Usage

primes( n)
Eratosthenes( n )
factorN( n )
allFactors( n )
prodN( fp )
is.prime( n )

Arguments

n

positive integer, number of primes, number to be factored, to be tested

fp

2-colummn matrix with prime factors and multiplicities

Value

primes

Generate the first n primes, also found in PRIMES.

Eratosthenes

Execute the sieve of Eratosthenes.

factorN

Determine the prime factors together with their multiplicities.

allFactors

generate all factors of n: 1..n.

prodN

Recombine factors, inverse of factorN.

is.prime

Check if positive integer is prime.

PRIMES

The first primes up to 17389.

Author(s)

Christian W. Hoffmann <hristian@echoffmann.ch>

Examples

(p <- factorN( 423))
## [1,]   3 47
## [2,]   2  1
# meaning 423 = 3^2 * 47^1
prodN(p) # 423
is.prime(.Machine$integer.max) # TRUE
is.prime(16) # FALSE
## check speed of your machine
  s <- Sys.time(); p<-primes(10^4);difftime(Sys.time(),s) 
## Time difference of 1.578922 secs  on my machine  
x <- factorN(.Machine$integer.max)

cwhmisc

Miscellaneous Functions for Math, Plotting, Printing, Statistics, Strings, and Tools

v6.6
GPL (>= 2)
Authors
Christian W. Hoffmann
Initial release
2018-08-24, 10:40:10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.