Project Euler5
Problem5
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?
1ãã20ã¾ã§ã®å ¨ã¦ã®æ°ã§å²ãåããæ°ã®ãã¡æå°ã®æ£ã®æ°ãæ±ããã¨ããåé¡ã
#1ãã20ã¾ã§ã®ç¯å²ã§ç´ æ°ãæ±ãã prime_num <- 2 for(i in 3:20){ if(any(i%%prime_num==0)){ next}else{ prime_num <- c(prime_num, i) } } #æ±ããç´ æ°ãããã res0 <- eval(parse(text = paste(collapse="*", prime_num))) #ç´ æ°ãNåãã¦1ãã20ã§å²ãã¨ããæä½ãç¹°ãè¿ã j <- 2 repeat{ res <- res0 * j if(sum(res %% 1:20)==0){ break }else{ j <- j + 1 } } res