def primeset(N): #N以下の素数をsetで求める.エラトステネスの篩O(√Nlog(N)) lsx = [1]*(N+1) for i in range(2,int(-(-N**0.5//1))+1): if lsx[i] == 1: for j in range(i,N//i+1): lsx[j*i] = 0 setprime = set() for i in range(2,N+1): if lsx[i] == 1: setprime.add(i) return setprime L,R = map(int,input().split()) # (A+B)*(B-A+1) = 2*P # A+B = 2 ^ B-A+1 = P -> A=B=1 P=1 x # A+B = P ^ B-A+1 = 2 -> B=A+1 P=2*A+1 o # A+B = 2*P ^ B-A+1 = 1 -> B=A P=A=B o # A+B = 1 ^ B-A+1 = 2*P -> x setp = primeset(2*10**6) ans = 0 for i in range(L,R+1): if i in setp: ans += 1 if (i+1 <= R) and (2*i + 1) in setp: ans += 1 print(ans)