Problem 47 2回目

Project EulerのスレッドからPythonでやった人のを拝借.エラトステネスの篩しながら素因数の数を数える.さっきのと考えは一緒だけどさっきのは余計なことやりすぎでひどかった.
どうもPythonだと3秒で終わるらしい.Rでは30秒かかった…
いやまあさっきよりはマシだけどさ.

limit <- 10^6
pr.fct <- numeric(limit)
count <- 0
for(i in 2:limit){
  if(pr.fct[i] == 0){                   #i is prime
    count <- 0
    for(j in seq(i, limit, i)){
      pr.fct[j] <- pr.fct[j] + 1
    }
  }
  if(pr.fct[i] == 4){
    count <- count + 1
    if(count==4){
      break
    }
  }else{
    count <- 0
  }
}
i-3