import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
import scala.io.StdIn._
object Main extends App {

  val isHamming = Array.fill(1000001){true}
  for (p ← prime(1000000).drop(3)) {
    for (j ← p until isHamming.length by p) {
      isHamming(j) = false
    }
  }
  val hammingNumbers = isHamming.indices.drop(1).filter(isHamming).toArray
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim.split(' ').map(_.toInt) match {
      case Array(m, n) ⇒ println(upperBound(hammingNumbers, n) - lowerBound(hammingNumbers, m))
        loop()
      case _ ⇒
    }
  }

  def lowerBound(array: Array[Int], target: Int): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (array(mid) < target) left = mid + 1
      else right = mid
    }
    right
  }
  def upperBound(array: Array[Int], target: Int): Int = {
    var left = 0
    var right = array.length
    while(left < right) {
      val mid = (left + right) / 2
      if (array(mid) <= target) left = mid + 1
      else right = mid
    }
    right
  }
  def prime(upperLimit: Int): Seq[Int] = {
    val isPrime = Array.fill(upperLimit + 1){true}
    for (i ← 2 to math.sqrt(upperLimit).round.toInt) {
      if (isPrime(i)) for (j ← i * i to upperLimit by i){
        isPrime(j) = false
      }
    }
    (2 to upperLimit).filter(isPrime)
  }
}
