#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
 
#define F first
#define S second
 
const int MOD = 1e9 + 7;//XXX
const int C = 26;//XXX
 
void add(int &x, int y){
	x += y;
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
}
 
int fix(int x){
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
	return x;
}
 
int pw(int a, int b){
	int ret = 1;
	while (b){
		if (b & 1)
			ret = 1ll*ret*a%MOD;
		b >>= 1;
		a = 1ll*a*a%MOD;
	}
	return ret;
}
 
const int MAXN = 1e6 + 10;

map<ll,ll> mp;
ll go(ll X, ll Y) {
	if(Y <= X) {
		return X - Y;
	}
	if(mp.count(Y))
		return mp[Y];
	if(Y % 2 == 0) {
		return mp[Y] = min(go(X, Y/2)+1, Y - X);
	}
	return mp[Y] = min(go(X, Y+1), go(X, Y-1)) + 1;
}

void solve() {
	ll X, Y;
	cin >> X >> Y;
	cout << go(X, Y) << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//cout << fixed << setprecision(6);
	
	int te = 1;	
	//cin >> te;
	for (int w = 1; w <= te; w++){
		//cout << "Case #" << w << ": ";
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;

const int MAX = 1e6+10;


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l,r;
	cin >> l >> r;
	ll res = 0;
	for(int i=2;i<=r;i++){
			int t = i;
			int fail = 0;
			int factors = 0;
			if( t%4 == 0){
					continue;
			}
			if( t%2 == 0){
					factors ++;
					t/=2;
			}
			for(int d =3;d*d<=t;d+=2){
					if( t%d ) continue;
					factors ++;
					if( t%(d*d) == 0 ){
							fail = 1;
							break;
					}
					t/=d;
			}
			if( t > 1) factors ++;
			if( fail ) continue;
			int sign = -1;
			if( factors%2 ) sign = 1;
			ll sumand = r/i - (l-1)/i;
			sumand = sumand*sumand*sign;
			res += sumand;
	}
	for(int i=max(2,l);i<=r;i++){
			res -= 2*(r/i) - 1;
	}
	cout << res << endl;
}
