Project Euler4
Problem4
A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.Find the largest palindrome made from the product of two 3-digit numbers.
åææ°ï¼å·¦ããèªãã§ãå³ããèªãã§ãåãæ°ï¼ãã¤ã2ã¤ã®3æ¡ã®æ°ã®ç©ã§è¡¨ããããã®ã®ãã¡æ大ã®ãã®ãæ±ãããã¨ããåé¡ã
1000000æªæºã®ç¯å²ã§åææ°ãã¾ãæ±ãã¦ããã®å¾100ãã999ã§çã£ç«¯ããé¤ãã¦çããæ±ããã
pal <- NULL for(a in 0:9){ for(b in 0:9){ for(c in 0:9){ pal0 <- a*100000 + b*10000 + c*1000 + c*100 + b*10 + a if(pal0 >= 10000){ pal <- c(pal, pal0) }else{ next} } } } for(num in 100:999){ res0 <- pal[pal%%num==0 & pal%/%num>=100 & pal%/%num<=999 & pal/num>=100 & pal/num<=999] if(sum(res0)==0){ next }else{ res <- unique(c(res, res0)) } } ans <- max(res)