Question

In: Computer Science

USE R 2520 is the smallest number that can be divided by each of the numbers...

USE R

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Now you need to create a function to find the smallest positive number that is evenly divisible by two numbers you input into the function. (For example, your input is 6 and 9, you need to find the smallest number which can be divided by 6, 7, 8 and 9)

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

=

# Find the GCD of the numbers x and y.

gcd = function (x, y) ifelse(x == 0, y, gcd(y %% x, x))

# Find the LCM here

lcm = function (x, y) x*y/gcd(x,y)

# Use the reduce function to do the process

# Pass the arguments start:stop to the function

print(Reduce(lcm, 1:10))

print(Reduce(lcm, 1:20))

print(Reduce(lcm, 6:9))

print(Reduce(lcm, 3:7))

=================


Related Solutions

Please use minimum cost rule to solve this problem. When the smallest numbers in a tie...
Please use minimum cost rule to solve this problem. When the smallest numbers in a tie in the same column?How to determine which one should be picked? And It they are in the same row and the demands are also the same, how to pick? Thank you Transportation Tableau Steel1 Steel 2 Steel 3 Dummy Plant 1 60 40 28 0 120 Plant 2 50 30 30 0 150 Plant 3 20 20 20 0 160 100 100 100 130...
Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
A number is prime if it can be divided exactly only by 1 and itself. Here...
A number is prime if it can be divided exactly only by 1 and itself. Here is an algorithm for checking if an input number is prime: function out = isprime(m)             for j:=2 to m-1             if mod(m,j) ==0 then             return “input is not a prime”             endif             endfor             return ”input is a prime” Let n denote the size of the input m, i.e. the number of bits in the binary expression for m. What is...
23 The relative frequency is the frequency in each class divided by the total number of...
23 The relative frequency is the frequency in each class divided by the total number of observations. A true B false 24, The scatter plot can visually show the relationship between two variables. A false B True 25 Ratio measurement scales indicate both rank and distance from a natural zero. A true B false 26 A time series diagram is a bar chart that displays the frequency of defect causes and is used to separate the "vital few" from the...
Let k ≥ 2. Use that R (the real numbers) is complete to show R^k is...
Let k ≥ 2. Use that R (the real numbers) is complete to show R^k is complete.
Define a class called Rational for rational numbers. Arational number is a number that can...
Define a class called Rational for rational numbers. A rational number is a number that can be represented as the quotient of two integers. For example, /2, 3/4, 64/2, and so forth are all rational numbers.Represent rational numbers as two private values of type int, numfor the numerator and den for the denominator. The class has a default constructor with default values (num = 0,den = 1), a copy constructor, an assignment operator and three friend functions for operator overloading...
Is rational number divided by an irrational number equal to irrational number or rational number?
Is rational number divided by an irrational number equal to irrational number or rational number? for example such as ( 5 / 2pi )
Take an unknown number of integers as input and print the second smallest number. If there...
Take an unknown number of integers as input and print the second smallest number. If there is no second smallest number in the sequence the program should print an error message and quit. Write a function that takes a vector as argument and that returns an int containing the second smallest number. If no such number exists, the function should throw an exception that in turn is caught in main. Your program should compute its answer with a complexity no...
Write a for-loop in MATLAB that generates a list of numbers such that each number is...
Write a for-loop in MATLAB that generates a list of numbers such that each number is the sum of the previous three. Initialize your list of numbers at the values of 0, 0 and 1. In other words, "0" is the first element of the list, "0" is the second element of the list, and "1" is the third element of the list. What is the 20th value in the list?
Given an array of numbers, find the index of the smallest array element (the pivot), for...
Given an array of numbers, find the index of the smallest array element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered. Example arr=[1,2,3,4,6] the sum of the first three elements, 1+2+3=6. The value of the last element is 6. Using zero based indexing, arr[3]=4 is the pivot between the two subarrays. The index of the pivot is 3. Function Description Complete the function balancedSum...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT