Description Usage Arguments Details Value Author(s) References See Also Examples
View source: R/IntegerFactorization.R
Quickly generates the complete factorization for many (possibly large) numbers.
1 | divisorsBig(v, namedList = FALSE)
|
v |
Vector of integers, numerics, string values, or elements of class bigz. |
namedList |
Logical flag. If |
Highly optimized algorithm to generate the complete factorization for many numbers. It is built specifically for the data type that is used in the gmp library (i.e. mpz_t
).
The main part of this algorithm is essentially the same algorithm that is implemented in divisorsRcpp from the RcppAlgos package. A modified merge sort algorithm is implemented to better deal with the mpz_t
data type. This algorithm avoids directly swapping elements of the main factor array of type mpz_t
but instead generates a vector of indexing integers for ordering.
See this stack overflow post for examples and benchmarks : R Function for returning ALL factors.
Returns an unnamed vector of class bigz if length(v) == 1
regardless of the value of namedList
.
If length(v) > 1
, a named/unnamed list of vectors of class bigz will be returned.
Joseph Wood
divisorsRcpp
, divisors
, factorize
1 2 3 4 5 6 7 8 9 10 | ## Get the complete factorization of a single number
divisorsBig(10^15)
## Or get the complete factorization of many numbers
set.seed(29)
myVec <- sample(-1000000:1000000, 1000)
system.time(myFacs <- divisorsBig(myVec))
## Return named list
myFacsWithNames <- divisorsBig(myVec, namedList = TRUE)
|
Loading required package: gmp
Attaching package: 'gmp'
The following objects are masked from 'package:base':
%*%, apply, crossprod, matrix, tcrossprod
Big Integer ('bigz') object of length 256:
[1] 1 2 4 5
[5] 8 10 16 20
[9] 25 32 40 50
[13] 64 80 100 125
[17] 128 160 200 250
[21] 256 320 400 500
[25] 512 625 640 800
[29] 1000 1024 1250 1280
[33] 1600 2000 2048 2500
[37] 2560 3125 3200 4000
[41] 4096 5000 5120 6250
[45] 6400 8000 8192 10000
[49] 10240 12500 12800 15625
[53] 16000 16384 20000 20480
[57] 25000 25600 31250 32000
[61] 32768 40000 40960 50000
[65] 51200 62500 64000 78125
[69] 80000 81920 100000 102400
[73] 125000 128000 156250 160000
[77] 163840 200000 204800 250000
[81] 256000 312500 320000 390625
[85] 400000 409600 500000 512000
[89] 625000 640000 781250 800000
[93] 819200 1000000 1024000 1250000
[97] 1280000 1562500 1600000 1953125
[101] 2000000 2048000 2500000 2560000
[105] 3125000 3200000 3906250 4000000
[109] 4096000 5000000 5120000 6250000
[113] 6400000 7812500 8000000 9765625
[117] 10000000 10240000 12500000 12800000
[121] 15625000 16000000 19531250 20000000
[125] 20480000 25000000 25600000 31250000
[129] 32000000 39062500 40000000 48828125
[133] 50000000 51200000 62500000 64000000
[137] 78125000 80000000 97656250 100000000
[141] 102400000 125000000 128000000 156250000
[145] 160000000 195312500 200000000 244140625
[149] 250000000 256000000 312500000 320000000
[153] 390625000 400000000 488281250 500000000
[157] 512000000 625000000 640000000 781250000
[161] 800000000 976562500 1000000000 1220703125
[165] 1250000000 1280000000 1562500000 1600000000
[169] 1953125000 2000000000 2441406250 2500000000
[173] 2560000000 3125000000 3200000000 3906250000
[177] 4000000000 4882812500 5000000000 6103515625
[181] 6250000000 6400000000 7812500000 8000000000
[185] 9765625000 10000000000 12207031250 12500000000
[189] 12800000000 15625000000 16000000000 19531250000
[193] 20000000000 24414062500 25000000000 30517578125
[197] 31250000000 32000000000 39062500000 40000000000
[201] 48828125000 50000000000 61035156250 62500000000
[205] 64000000000 78125000000 80000000000 97656250000
[209] 100000000000 122070312500 125000000000 156250000000
[213] 160000000000 195312500000 200000000000 244140625000
[217] 250000000000 312500000000 320000000000 390625000000
[221] 400000000000 488281250000 500000000000 625000000000
[225] 781250000000 800000000000 976562500000 1000000000000
[229] 1250000000000 1562500000000 1600000000000 1953125000000
[233] 2000000000000 2500000000000 3125000000000 3906250000000
[237] 4000000000000 5000000000000 6250000000000 7812500000000
[241] 8000000000000 10000000000000 12500000000000 15625000000000
[245] 20000000000000 25000000000000 31250000000000 40000000000000
[249] 50000000000000 62500000000000 100000000000000 125000000000000
[253] 200000000000000 250000000000000 500000000000000 1000000000000000
user system elapsed
0.004 0.001 0.005
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.