write a function get factors ( ) ( ) that takes a number x and returns a
Fantastic news! We've Found the answer you've been seeking!
Question:
write a function get factors() that takes a number x and returns a list object. The list
object should contain a vector of unique prime factors of x and the corresponding exponents.
Additionally, write one helper function is prime() that returns a logical vector depending on
whether or not the elements in x are prime. A good way to test this function should be:
x <− sample(x =1e4, size =1)
y <− get_factors(x)
this_works <− prod(y$primes^y$exponents)== x & all(is_prime(y$primes))
It is a necessary, but not sufficient, condition that this works == TRUE for your function to work
as intended. (It will largely depend on if your is prime() function is correct.)
Related Book For
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis
Posted Date: