#include<iostream>
#include<cstdio>
using namespace std;

#define rep(i, n)for((i) = 0;(i) < (n);++(i))
#define ma 1001001

int res[ma];
bool isp[ma];
int main(void){
	int i, j, n, m;
	rep(i, ma){
		res[i] = 1;
		isp[i] = true;
	}
	isp[0] = false; isp[1] = false; res[0] = 0;
	for(int i = 2;i < ma;++i){
		if(!isp[i])continue;
		for(j = i + i;j < ma;j+=i)isp[j] = false;
		if(i > 5){
			for(j = i;j < ma;j+=i)res[j] = 0;
		}
	}
	rep(i, ma - 1)res[i + 1] += res[i];

	for(;;){
		scanf("%d%d", &m, &n);
		if(m == 0)break;
		printf("%d\n", res[n] - res[m - 1]);
	}
}