#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

#define D long long
#define F double
#define mmm(a,b) memset(a,b,sizeof(a))
D read(){ D ans=0; char last=' ',ch=getchar();
while(ch<'0' || ch>'9')last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans; return ans;
}
const int N=10000000;
const F pi=acos(-1);

D n,m,_n,_m,p=1e9+7,mi;
D f[N+9],mu[N+9];
D pri[664600],now;
bool vis[N+9];
void init(){
    mmm(vis,0);mi=min(m,n);now=0;
    for(D i=1;i<=mi;i++){
        f[i]=((n/i)-(_n-1)/i)*((m/i)-(_m-1)/i);
    }
    mu[1]=1;
    for(int i=2;i<=N;i++){
        if(!vis[i]){
            pri[++now]=i;
            mu[i]=-1;
        }
        for(int j=1;j<=now&&i*pri[j]<=N;j++){
            vis[i*pri[j]]=true;
            if(i%pri[j])mu[i*pri[j]]=-mu[i];//出现新的素数 mu=-mu
            else{
                mu[i*pri[j]]=0;             //出现相同素数
                break;
            }
        }
    }
}

int main(){
	LL l, r;
	cin >> l >> r;
    _n=l,n=r,_m=l,m=r;
    init();
    D coprime=0;
    for(int i=1;i<=mi;i++)
        coprime+=f[i]*mu[i];
	
	coprime /= 2;

	// printf("coprime = %lld\n", coprime);

	LL num = r - l + 1;
	LL ans = num * (num - 1) / 2;
	// printf("all: %lld\n", ans);

	LL times = 0;
	for (LL i = l; i <= r; i++) {
		times += (r / i - 1);
	}

	LL ret = 0;
	if (l != 1) {
		ret = (ans - times - coprime) * 2;
	} else {
		ret = (ans - coprime - times + r - 1) * 2;
	}


	// printf("times: %lld\n", times);

    printf("%lld\n", ret);
}
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

void bfs(vector<vector<int>> &G, int N, int s, vector<int> &dist) {
    dist.assign(N,-1);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    while(que.size()) {
        int v = que.front();
        que.pop();
        for(int nv : G[v]) {
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
}

int main() {
    int N,M; cin >> N >> M;
    vecveci G(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
    }

    ll ans = 0;

    REP(s,N) {
        veci dist(N,-1);
        bfs(G,N,s,dist);
        REP(g,N) {
            if(dist[g] != -1) ans++;
        }
    }

    cout << ans << endl;
    return 0;
}