#include<bits/stdc++.h>
#define ll unsigned long long int
#define N 2000001
using namespace std;
int p[N+1];
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
for(i=2;i<=N;i++)
{
if(p[i] == 0)
{
for(j=2;i*j<=N;j++)
{
p[i*j] = 1;
}
}
}
}
int phi[N+1];
void phifunction()
{
ll i, j;
for(i=1;i<=N;i++)
phi[i] = i;
for(i=2;i<=N;i++)
{
if(p[i] == 0)
{
for(j=i;j<=N;j+=i)
{
phi[j] = phi[j]/i*(i-1);
}
}
}
}
int s[N+1];
void sodf()
{
ll i, j, n;
s[1] = 0;
for(i=2;i<=N;i++)
{
n = i;
j = 0;
while(n != 1)
{
n = phi[n];
j++;
}
s[i] = j;
}
}
int main()
{
prime();
phifunction();
sodf();
ll a, n, m, i, c, j;
while(cin >> a)
{
for(i=1;i<=a;i++)
{
cin >> n >> m;
c = 0;
for(j=n;j<=m;j++)
{
c += s[j];
}
cout << c << endl;
}
}
return 0;
}
#define ll unsigned long long int
#define N 2000001
using namespace std;
int p[N+1];
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
for(i=2;i<=N;i++)
{
if(p[i] == 0)
{
for(j=2;i*j<=N;j++)
{
p[i*j] = 1;
}
}
}
}
int phi[N+1];
void phifunction()
{
ll i, j;
for(i=1;i<=N;i++)
phi[i] = i;
for(i=2;i<=N;i++)
{
if(p[i] == 0)
{
for(j=i;j<=N;j+=i)
{
phi[j] = phi[j]/i*(i-1);
}
}
}
}
int s[N+1];
void sodf()
{
ll i, j, n;
s[1] = 0;
for(i=2;i<=N;i++)
{
n = i;
j = 0;
while(n != 1)
{
n = phi[n];
j++;
}
s[i] = j;
}
}
int main()
{
prime();
phifunction();
sodf();
ll a, n, m, i, c, j;
while(cin >> a)
{
for(i=1;i<=a;i++)
{
cin >> n >> m;
c = 0;
for(j=n;j<=m;j++)
{
c += s[j];
}
cout << c << endl;
}
}
return 0;
}
Comments
Post a Comment