2014年04月09日

# Q

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?


## R

### First Version

Factor <- 1:20
j <-3
temp <-1
i <-2
while(i<=10)
{
while(j>i & j<=10)
{
if((i*j)<=20)  temp<- c(temp,(i*j))
j <- j+1
}
i <- i+1
}
Factor <- setdiff(Factor,temp)
Num <-2520
repeat
{
for(k in Factor)
{
if(Num %% k !=0) break
}
if(k==max(Factor)) break
Num <- Num+1
}
print(Num)