(This article was first published on

**The Devil is in the Data**, and kindly contributed to R-bloggers)Euler Problem 5 relates to the divisibility of numbers.

## Euler Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

## Solution

The solution will also be divisible by the number 1 to 10 so we can start at 2520 and increment by 2520. The loop checks whether the number is divisible by the numbers 1 to 20.

# Start as high as possible i <- 2520 # Check consecutive numbers for divisibility by 1:20 while (sum(i%%(1:20)) != 0) { i <- i + 2520 # Increase by smallest number divisible by 1:10 } answer <- i

The post Euler Problem 5: Smallest Multiple appeared first on The Devil is in the Data.

To

**leave a comment**for the author, please follow the link and comment on their blog:**The Devil is in the Data**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...