Algorithms for division that provide a quotient and remainder.

naivediv(m, n)

longdiv(m, n)

Arguments

m

the dividend

n

the divisor

Value

the quotient and remainder as a list

Details

The naivediv divides m by n by using repeated division. The longdiv function uses the long division algorithm in binary.

See also

Examples

a <- floor(runif(1, 1, 1000))
b <- floor(runif(1, 1, 100))
naivediv(a, b)
#> $quotient
#> [1] 0
#> 
#> $remainder
#> [1] 81
#> 
longdiv(a, b)
#> $quotient
#> [1] 0
#> 
#> $remainder
#> [1] 81
#>