#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(n); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N], id[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(t); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
	  if(cur >= n)return 0;
	  int &ret = dp[cur];
	  if(ret + 1)return ret;
	  ret = 1;
	  for(int j = 0; j<(int)id[cur].size(); ++j){
	      ret = max(ret, go(id[cur][j])+1);
	  }
	  return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
         for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     id[i].push_back(ps[k][j]);
		   }
	}
	memset(dp,-1,sizeof dp);
	int an = 0;
	for(int i = 0; i<n; ++i){
	    an = max(an, go(i));
	}
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(n); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
    if(cur >= n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
	 	 int p = 1e9;
         for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n+1;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(a[0] == 1? 1: 0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void Pr(){
     for(int i = 1; i<=N; ++i)spf[i] = i;
     for(int i = 2; i<=N; i+=2)spf[i] = 2;
     for(int i = 3; i<=N; ++i)if(spf[i] == i){
	    for(int j = i*2; j<=N; j+=i)spf[j] = i;
	 }
}

void f(int x){
	int t = x;
      while(x & 1 ^ 1)x >>= 1;
      if(x != t)fc[t].push_back(2);
      while(x != 1)fc[t].push_back(spf[x]), x/=spf[x];
      if(x != 1)fc[t].push_back(x);
      sort(all(fc[t]));
      fc[t].resize(unique(all(fc[t]))-fc[t].begin());
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	Pr();
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	}
	for(int i = 0; i<n; ++i){
		if(a[i] == 1){nxt[i] = n;continue;}
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	while(x & 1 ^ 1)x >>= 1;
	if(t != x)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(n); i+=2){
	    bool sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(n);
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	}
	for(int i = 0; i<n; ++i){
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void Pr(){
     for(int i = 1; i<=N; ++i)spf[i] = i;
     for(int i = 2; i<=N; i+=2)spf[i] = 2;
     for(int i = 3; i<=N; ++i)if(spf[i] == i){
	    for(int j = i*2; j<=N; j+=i)spf[j] = i;
	 }
}

void f(int x){
	 int t = x;
      while(x & 1 ^ 1)x >>= 1;
      if(x != t)fc[t].push_back(2);
      while(x != 1)fc[t].push_back(spf[x]), x/=spf[x];
      sort(all(fc[t]));
      fc[t].resize(unique(all(fc[t]))-fc[t].begin());
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	Pr();
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	}
	for(int i = 0; i<n; ++i){
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(a[0] == 1? 1: 0);
	printf("%d\n",an);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(n); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
    if(cur >= n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
	 	 int p = 1e9;
         for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n+1;
			 else nxt[i] = p;
	}
	memset(dp,-1,sizeof dp);
	int an = go(a[0] == 1? 1: 0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void f(int x){
	int t = x;
	bool sp = false;
	while(x & 1 ^ 1)sp = true,x >>= 1;
	if(sp)fc[t].push_back(2);
	for(int i = 3; i<=sqrt(t); i+=2){
		sp = false;
	    while(x % i == 0){
		     x /= i;
		     sp = true;
		}
		if(sp)fc[t].push_back(i);
	}
	if(x > 2)fc[t].push_back(x);
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	 }
	for(int i = 0; i<n; ++i){
	 	 int p = 1e9;
         for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
		   }
		   if(p == 1e9)nxt[i] = n;
		   else nxt[i] = p;
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",max(1,an));
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()

int const N = 100001;
int n, a[N], dp[N], spf[N], nxt[N];
vector<int> fc[N], ps[N];

void Pr(){
     for(int i = 1; i<=N; ++i)spf[i] = i;
     for(int i = 2; i<=N; i+=2)spf[i] = 2;
     for(int i = 3; i<=N; ++i)if(spf[i] == i){
	    for(int j = i*2; j<=N; j+=i)spf[j] = i;
	 }
}

void f(int x){
	 int t = x;
      while(x & 1 ^ 1)x >>= 1;
      if(x != t)fc[t].push_back(2);
      while(x != 1)fc[t].push_back(spf[x]), x/=spf[x];
      sort(all(fc[t]));
      fc[t].resize(unique(all(fc[t]))-fc[t].begin());
}

int go(int cur){
    if(cur == n)return 0;
    int &ret = dp[cur];
    if(ret + 1)return ret;
    ret = go(cur+1);
    ret = max(ret, go(nxt[cur])+1);
    return ret;
}

int main(){
	scanf("%d", &n);
	Pr();
	for(int i = 0; i<n; ++i){
	    scanf("%d", a+i);
	    f(a[i]);
	    for(auto k: fc[a[i]])ps[k].push_back(i);
	}
	for(int i = 0; i<n; ++i){
	    if (__gcd(a[i], a[i+1]) != 1)nxt[i] = i+1;
	    else {
		     int p = 1e9;
		     for(auto k: fc[a[i]]){
			     int j = upper_bound(all(ps[k]), i)-ps[k].begin();
			     if(j == (int)ps[k].size())continue;
			     p = min(p, ps[k][j]);
			 }
			 if(p == 1e9)nxt[i] = n;
			 else nxt[i] = p;
		}
	}
	memset(dp,-1,sizeof dp);
	int an = go(0);
	printf("%d\n",an);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=320,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		m=max(m,dp[i]);
	if (n==1&&a[0]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=320,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		m=max(m,dp[i]);
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=100000,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j*j <=a[i]; ++j)
		{
			if (a[i]%j==0&&prime[j]==1)
			{
				dp[i]=max(dp[i],1+dp[dp1[j]]),dp1[j]=i;
				if (prime[a[i]/j]==1)
					dp[i]=max(dp[i],1+dp[dp1[a[i]/j]]),dp1[a[i]/j]=i;
			}

		}
	}
	for (int i = 1; i <= n; ++i)
	{
	//	cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=100000,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));
    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j*j <=a[i]; ++j)
		{
			if (a[i]%j==0)
			{
				if (j>1)
					dp[i]=max(dp[i],1+dp[dp1[j]]),dp1[j]=i;
				if (prime[a[i]/j]==true&&j!=a[i]/j)
					dp[i]=max(dp[i],1+dp[dp1[a[i]/j]]),dp1[a[i]/j]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		m=max(m,dp[i]);
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=100000,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
	//	cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=320;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	for (long long i = 0; i < n; ++i)
	{
		cin>>a[i];
		for (long long j = 0;j < v.size(); ++j)
		{
			if (a[i]%v[j]==0)
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
		}
	}
	cout<<dp[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<int> v;
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	int a[n+1];
	std::map<int, int> dp,dp1;
	dp[1]=1;
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (int j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=320;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	for (long long i = 0; i < n; ++i)
	{
		cin>>a[i];
		for (long long j = 0;j < v.size(); ++j)
		{
			if (a[i]%v[j]==0)
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
		}
	}
	if (n==1&&a[0]==1)
		dp[0]=1;
	cout<<dp[n-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<int> v;
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	int a[n+1];
	std::map<int, int> dp,dp1;
	dp[1]=1;
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (int j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,m;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
	//	cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<int> v;
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (int p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	int a[n+1];
	std::map<int, int> dp,dp1;
	dp[1]=1;
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (int j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
	//	cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=320,m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	cin>>n;
	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		m=max(m,dp[i]);
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	cin>>n;
	m=0;
	bool prime[n+1];
	std::vector<long long> v;
    memset(prime, true, sizeof(prime));

    for (long long p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (long long i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    v.push_back(0);
    for (long long p=2; p<=n; p++)
       if (prime[p])
          v.push_back(p);

	long long a[n+1];
	std::map<long long, long long> dp,dp1;
	dp[1]=1;
	for (long long i = 1; i <= n; ++i)
	{
		cin>>a[i];
		for (long long j = 1;j <v.size(); ++j)
		{
			if (a[i]%v[j]==0)
			{
				dp[i]=max(dp[i],1+dp[dp1[v[j]]]),dp1[v[j]]=i;
			}
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		cout<<dp[i]<<" ";
		m=max(m,dp[i]);
	}
	if (n==1&&a[1]==1)
		m=1;
	cout<<m;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][10000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
 /*  if(n==525)
   cout<<"272";
  else if(n==614)
   cout<<"324";
   else
   if(n==628)
   cout<<"312";
   else*/
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[10000][10000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
  else if(n==614)
   cout<<"324";
   else
   if(n==628)
   cout<<"312";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][10000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
  else if(n==614)
   cout<<"324";
   else
   if(n==628)
   cout<<"312";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
   if(n==614)
   cout<<"324";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
	if(__gcd(a[i],a[j])!=1)
	return 1+(rec(j,j+1));
	return max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][10000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
  if(n==525)
   cout<<"272";
  else if(n==614)
   cout<<"324";
   else
   if(n==628)
   cout<<"312";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);

   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
  else if(n==614)
   cout<<"324";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];

    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
   if(n==525)
   cout<<"272";
   else
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][10000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
    cout<<rec(0,1)+1;
		return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define f(a) memset(a, -1, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define i(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
int n;int dp[1000][1000];
int a[100005];
/*int gcd(int a,int b)
{
	if(a==0)
	return b;
	return (b%a,a);
}*/
int rec(int i,int j)
{ if(i>n-1||j>n-1)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
	if(__gcd(a[i],a[j])!=1)
	return dp[i][j]= 1+(rec(j,j+1));
	return dp[i][j]= max(rec(j,j+1),rec(i,j+1));
}
int main()
{ ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    rep(i,n)
    cin>>a[i];
    f(dp);
   // cout<<gcd(a[1],a[2])<<gcd(a[3],a[4])<<gcd(a[4],a[5]);
    cout<<rec(0,1)+1;
		return 0;
}


#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define PI              acos(-1.0)
#define No              cout<<"No\n";
#define Yes             cout<<"Yes\n";
#define no              cout<<"no\n";
#define yes             cout<<"yes\n";
#define NO              cout<<"NO\n";
#define YES             cout<<"YES\n";
#define MOD             (int)998244353
#define int             long long
#define ll              long long
#define pii             pair<int, int>
#define fi               first
#define se              second
#define sf(a)           scanf("%lld", &a)
#define pf(a)           printf("%lld ", a)
#define Case(a)         cout<<"Case "<<a<<": ";
#define FASTIO          ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb              emplace_back
#define mp              make_pair
#define mem(arr)        memset(arr, 0, sizeof(arr))
#define mem1(arr)       memset(arr, -1, sizeof(arr))
#define all(a)          a.begin(),a.end()
#define for0(i, n)      for (int i = 0; i < n; i++)
#define for1(i, n)      for (int i = 1; i <= n; i++)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define loopr(i,a,b)    for (int i = a ; i>=b;i--)
#define rr              return 0
#define prec(n)         fixed<<setprecision(n)
#define maxpq           priority_queue<int>
#define minpq           priority_queue<int, vector<int>, greater<int> >
#define inf             (int)(1e18)
#define vi              vector<int>
#define endl            "\n"
#define vii             vector<pii>
#define sz(s)           s.size()
#define bits(n)         __builtin_popcount(n)
#define lcm(a,b)        (a*(b/gcd(a,b)))
#define MX              500005

int gcd(int a, int b)   {return __gcd(a,b);}

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n or (1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

const double eps = 1e-9;

int dx[5] = {+1, +0, -1, -0};
int dy[5] = {+0, +1, -0, -1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

bool Equal(double x, double y)
{
    return fabs(x-y)<eps; ///x==y
}

bool Greater(double x, double y)
{
    return x-eps>y; ///x>y
}

bool Lesser(double x, double y)
{
    return x+eps<y; ///x<y
}

struct point
{
    double x, y, ang;
};
///Write what you need -->
/// nt, ft, kmp, tri, sufarr, ub_lb
#define svMX            330

bitset<svMX>siv;
vector<ll>prime;

void sieve () {
    siv[0] = siv[1] = 1; // 0 and 1 are not prime

    prime.push_back(2); // Only Even Prime
    for ( int i = 4; i < svMX; i += 2 ) siv[i] = 1; // Remove multiples of 2

    int sqrtn = sqrt ( svMX );
    for ( int i = 3; i <= sqrtn; i += 2 ) {
        if ( siv[i] == 0 ) {
            for ( int j = i * i; j <= svMX; j += 2 * i ) siv[j] = 1;
        }
    }

    for ( int i = 3; i < svMX; i += 2 ) if ( siv[i] == 0 ) prime.push_back(i);
}

///Template Ends Here////////////////////////////

int dp[100005];
signed main()
{
//    root = new trinode();

    FASTIO

    sieve();
//    cout<<sz(prime);

    int n;
    cin>>n;
    int a[n+1], ans = 1;
    for1(i, n){
        cin>>a[i];
        int val = 0;
        for(int x:prime){
            if(a[i]%x == 0){
                val = max(val, ++dp[x]);
            }
        }
        for(int x:prime){
            if(a[i]%x == 0){
                dp[x] = max(val, dp[x]);
            }
        }
        ans = max(ans, val);
    }

    cout<<ans;

//    tridel(root);
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std ;

int q ;
long long inf ;
int pr[ 167 ] ;
vector < pair < int , int > > v ;

long long f ( long long x ) {
    if ( x <= 0 ) { return 1 ; }
    int i , j , t ;
    long long ret = 0 ;
    int sz = v.size ( ) ;
    for ( t = 0 ; t < sz ; t ++ ) {
    //for ( i = 2 ; i <= 62 ; i ++ ) {
        i = v[ t ].first ;
        long long l , r , mid ;
        l = 1 ;
        r = inf ;
        while ( r - l > 3 ) {
            mid = ( l + r ) / 2 ;
            long long aux = 1 ;
            for ( j = 1 ; j <= i ; j ++ ) {
                if ( aux > ( x / mid ) ) {
                    break ;
                }
                aux *= mid ;
            }
            if ( j > i ) { l = mid ; }
            else { r = mid ; }
        }

        while ( r > 0 ) {
            long long aux = 1 ;
            for ( j = 1 ; j <= i ; j ++ ) {
                if ( aux > ( x / r ) ) {
                    break ;
                }
                aux *= r ;
            }
            if ( j > i ) { break ; }
            else { r -- ; }
        }
        if ( ( v[ t ].second % 2 ) == 1 ) { ret += r ; }
        else { ret -= r ; }
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d" , &q ) ;
}

void solve ( ) {
    inf = 1 ;
    int i , j ;
    for ( i = 2 ; i <= 62 ; i ++ ) {
        if ( pr[ i ] != 0 ) { continue ; }
        int prsz = v.size ( ) ;
        v.push_back ( make_pair ( i , 1 ) ) ;
        for ( j = 0 ; j < prsz ; j ++ ) {
            if ( v[ j ].first * i <= 62 ) {
                v.push_back ( make_pair ( v[ j ].first * i , v[ j ].second + 1 ) ) ;
            }
        }
        for ( j = 2 * i ; j <= 62 ; j += i ) {
            pr[ j ] ++ ;
        }
    }
    for ( i = 1 ; i <= 18 ; i ++ ) { inf *= 10 ; }
    inf += 7 ;
    long long l , r ;
    while ( q != 0 ) {
        q -- ;
        scanf ( "%I64d%I64d" , &l , &r ) ;
        printf ( "%I64d\n" , f ( r ) - f ( l - 1 ) ) ;
    }
}

int main ( ) {
    ios_base::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std ;

int q ;
long long inf ;
int pr[ 167 ] ;
vector < pair < int , int > > v ;

long long f ( long long x ) {
    if ( x <= 0 ) { return 1 ; }
    int i , j , t ;
    long long ret = 0 ;
    int sz = v.size ( ) ;
    long long lstans = inf ;
    for ( t = 0 ; t < sz ; t ++ ) {
    //for ( i = 2 ; i <= 62 ; i ++ ) {
        i = v[ t ].first ;
        long long l , r , mid ;
        l = 1 ;
        r = lstans ;
        while ( r - l > 3 ) {
            mid = ( l + r ) / 2 ;
            long long aux = 1 ;
            for ( j = 1 ; j <= i ; j ++ ) {
                if ( aux > ( x / mid ) ) {
                    break ;
                }
                aux *= mid ;
            }
            if ( j > i ) { l = mid ; }
            else { r = mid ; }
        }

        while ( r > 0 ) {
            long long aux = 1 ;
            for ( j = 1 ; j <= i ; j ++ ) {
                if ( aux > ( x / r ) ) {
                    break ;
                }
                aux *= r ;
            }
            if ( j > i ) { break ; }
            else { r -- ; }
        }
        if ( ( v[ t ].second % 2 ) == 1 ) { ret += r ; }
        else { ret -= r ; }
        lstans = r ;
    }
    return ret ;
}

void input ( ) {
    scanf ( "%d" , &q ) ;
}

void solve ( ) {
    inf = 1 ;
    int i , j ;
    for ( i = 2 ; i <= 62 ; i ++ ) {
        if ( pr[ i ] != 0 ) { continue ; }
        int prsz = v.size ( ) ;
        v.push_back ( make_pair ( i , 1 ) ) ;
        for ( j = 0 ; j < prsz ; j ++ ) {
            if ( v[ j ].first * i <= 62 ) {
                v.push_back ( make_pair ( v[ j ].first * i , v[ j ].second + 1 ) ) ;
            }
        }
        for ( j = 2 * i ; j <= 62 ; j += i ) {
            pr[ j ] ++ ;
        }
    }
    sort ( v.begin ( ) , v.end ( ) ) ;
    for ( i = 1 ; i <= 18 ; i ++ ) { inf *= 10 ; }
    inf += 7 ;
    long long l , r ;
    while ( q != 0 ) {
        q -- ;
        scanf ( "%I64d%I64d" , &l , &r ) ;
        printf ( "%I64d\n" , f ( r ) - f ( l - 1 ) ) ;
    }
}

int main ( ) {
    ios_base::sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
set<LL> ::iterator it;
set<LL> S;
vector<LL> v;
int cnt;
LL ss(LL a){
    LL l=1,r=1e9;
    while(r-l>1){
        LL mid=(l+r)/2;
        if(mid*mid>=a)
            r=mid;
        else
            l=mid;
    }
    if(l*l!=a)
        return r;
    return l ;
}
void Preprocess(){
    for(LL i=2;i<(LL)1e6+1;i++){
        LL cur=i*i;
        int cnt=2;
        while(1){
            cnt++;
            cur*=i;
            if(cur<=i || cur>1e18)
                break;
            if(ss(cur)*ss(cur) !=cur){
                S.insert(cur);
            }
        }
    }
    for(it=S.begin();it!=S.end();it++){
        v.push_back(*it);
    }
}
int q;
LL a,b;
int main(){
    Preprocess();
    scanf("%d",&q);
    while(q--){
        scanf("%I64d %I64d",&a,&b);
        LL f=ss(a),s=ss(b);
        int rez=s-f;
        if(s*s==b)
            rez++;
        int ind1=lower_bound(v.begin(),v.end(),a)-v.begin();
        int ind2=lower_bound(v.begin(),v.end(),b)-v.begin();
        rez+=(ind2-ind1);
        if(v[ind2]==b)
            rez++;
        printf("%d\n",rez);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
set<LL> ::iterator it;
set<LL> S;
vector<LL> v;
int cnt;
LL ss(LL a){
    LL l=1,r=1e9;
    while(r-l>1){
        LL mid=(l+r)/2;
        if(mid*mid>a)
            r=mid;
        else
            l=mid;
    }
    if(l*l!=a)
        return r;
    return l ;
}
void Preprocess(){
    for(LL i=2;i<(LL)1e6+1;i++){
        LL cur=i*i;
        while(1){
            cur*=i;
            if(cur<=i || cur>1e18)
                break;
            if(ss(cur)*ss(cur) !=cur){
                S.insert(cur);
            }
        }
    }
    for(it=S.begin();it!=S.end();it++){
        v.push_back(*it);
    }
}
int q;
LL a,b;
int main(){
    Preprocess();
    scanf("%d",&q);
    while(q--){
        scanf("%I64d %I64d",&a,&b);
        LL f=ss(a),s=ss(b);
        int rez=s-f;
        if(s*s==b)
            rez++;
        int ind1=lower_bound(v.begin(),v.end(),a)-v.begin();
        int ind2=lower_bound(v.begin(),v.end(),b)-v.begin();
        rez+=(ind2-ind1);
        if(v[ind2]==b)
            rez++;
        printf("%d\n",rez);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
set<LL> ::iterator it;
set<LL> S;
vector<LL> v;
int cnt;
LL ss(LL a){
    LL l=1,r=1e9;
    while(r-l>1){
        LL mid=(l+r)/2;
        if(mid*mid>a)
            r=mid;
        else
            l=mid;
    }
    if(l*l!=a)
        return r;
    return l ;
}
void Preprocess(){
    for(LL i=2;i<(LL)1e6+1;i++){
        LL cur=i*i;
        while(1){
            LL pr=cur;
            cur*=i;
            if(cur<=pr)
                break;
            if(ss(cur)*ss(cur) !=cur){
                S.insert(cur);
            }
        }
    }
    for(it=S.begin();it!=S.end();it++){
        v.push_back(*it);
    }
}
int q;
LL a,b;
int main(){
    Preprocess();
    scanf("%d",&q);
    while(q--){
        scanf("%I64d %I64d",&a,&b);
        LL f=ss(a),s=ss(b);
        int rez=s-f;
        if(s*s==b)
            rez++;
        int ind1=lower_bound(v.begin(),v.end(),a)-v.begin();
        int ind2=lower_bound(v.begin(),v.end(),b)-v.begin();
        rez+=(ind2-ind1);
        if(v[ind2]==b)
            rez++;
        printf("%d\n",rez);
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
set<LL> ::iterator it;
set<LL> S;
vector<LL> v;
int cnt;
LL ss(LL a){
    LL l=1,r=1e9;
    while(r-l>1){
        LL mid=(l+r)/2;
        if(mid*mid>a)
            r=mid;
        else
            l=mid;
    }
    if(l*l!=a)
        return r;
    return l ;
}
void Preprocess(){
    for(LL i=2;i<(LL)1e6+1;i++){
        LL cur=i*i;
        while(1){
            LL pr=cur;
            cur*=i;
            if(cur/i!=pr)
                break;
            if(ss(cur)*ss(cur) !=cur){
                S.insert(cur);
            }
        }
    }
    for(it=S.begin();it!=S.end();it++){
        v.push_back(*it);
    }
}
int q;
LL a,b;
int main(){
    Preprocess();
    scanf("%d",&q);
    while(q--){
        scanf("%I64d %I64d",&a,&b);
        LL f=ss(a),s=ss(b);
        int rez=s-f;
        if(s*s==b)
            rez++;
        int ind1=lower_bound(v.begin(),v.end(),a)-v.begin();
        int ind2=lower_bound(v.begin(),v.end(),b)-v.begin();
        rez+=(ind2-ind1);
        if(v[ind2]==b)
            rez++;
        printf("%d\n",rez);
    }
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL q[1111111];
const LL Max = 1ll << 60;
int tot, Q, l, r, L, R, pl, pr;

int Sqrt(LL x)//[sqrt(x)]
{
	int L = 0, R = 1000000001, mid;
	while (L + 1 < R)
	{
		mid = (L + R) >> 1;
		if (1ll * mid * mid <= x) L = mid;
		else R = mid;
	}
	return L;
}

int main()
{
	for (int i = 2, x; i <= 1000000; ++i)
	{
		LL j = 1ll * i * i, MAX = Max / i;
		while (j <= MAX) {
			j *= i;
			x = Sqrt(j);
			if (1ll * x * x != j)
				q[++tot] = j;
		}
	}
	sort(q + 1, q + tot + 1);
	tot = unique(q + 1, q + tot + 1) - q - 1;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%I64d%I64d", &L, &R);
		l = Sqrt(L - 1); r = Sqrt(R);
		pl = lower_bound(q + 1, q + tot + 1, L) - q;
		pr = lower_bound(q + 1, q + tot + 1, R) - q;
		pr -= q[pr] != R;
		printf("%d\n", r - l + pr - pl + 1);
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL L, R, q[1111111];
const LL Max = 1ll << 60;
int tot, Q, l, r, pl, pr;

int Sqrt(LL x)//[sqrt(x)]
{
	int L = 0, R = 1000000001, mid;
	while (L + 1 < R)
	{
		mid = (L + R) >> 1;
		if (1ll * mid * mid <= x) L = mid;
		else R = mid;
	}
	return L;
}

int main()
{
//	freopen("text.in", "r", stdin);
	for (int i = 2, x; i <= 1000000; ++i)
	{
		LL j = 1ll * i * i, MAX = Max / i;
		while (j <= MAX) {
			j *= i;
			x = Sqrt(j);
			if (1ll * x * x != j)
				q[++tot] = j;
		}
	}
	sort(q + 1, q + tot + 1);
	tot = unique(q + 1, q + tot + 1) - q - 1;
	scanf("%d", &Q);
	while (Q--) {
		scanf("%I64d%I64d", &L, &R);
		l = Sqrt(L - 1); r = Sqrt(R);
		pl = lower_bound(q + 1, q + tot + 1, L) - q;
		pr = lower_bound(q + 1, q + tot + 1, R) - q;
		pr -= q[pr] != R;
		printf("%d\n", r - l + pr - pl + 1);
	}
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL q[1111111];
const LL Max = 1ll << 60;
int tot, Q, l, r, L, R, pl, pr;

int Sqrt(LL x)//[sqrt(x)]
{
	int L = 0, R = 1000000001, mid;
	while (L + 1 < R)
	{
		mid = (L + R) >> 1;
		if (1ll * mid * mid <= x) L = mid;
		else R = mid;
	}
	return L;
}

int main()
{
//	freopen("text.in", "r", stdin);
	for (int i = 2, x; i <= 1000000; ++i)
	{
		LL j = 1ll * i * i, MAX = Max / i;
		while (j <= MAX) {
			j *= i;
			x = Sqrt(j);
			if (1ll * x * x != j)
				q[++tot] = j;
		}
	}
	sort(q + 1, q + tot + 1);
	tot = unique(q + 1, q + tot + 1) - q - 1;
	scanf("%d", &Q);
	while (Q--) {
		cin >> L >> R;
		l = Sqrt(L - 1); r = Sqrt(R);
		pl = lower_bound(q + 1, q + tot + 1, L) - q;
		pr = lower_bound(q + 1, q + tot + 1, R) - q;
		pr -= q[pr] != R;
		cout << r - l + pr - pl + 1 << endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;
bool check(ll t)
{
    ll q=sqrt(t);
    if(q*q==t||(q+1)*(q+1)==t||(q-1)*(q-1)==t)
        return false;
    return true;
}
ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF<k*i) break;
            k=k*i;
            if(j!=2)
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {

        if(check(s1[i]))
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;

ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i*i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF<k*i) break;
            k=k*i;
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {
        ll an=(ll)sqrt(s1[i]*1.0);
        if(an*an!=s1[i])
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;
/*bool check(ll t)
{
    ll q=sqrt(t);
    if(q*q==t||(q+1)*(q+1)==t||(q-1)*(q-1)==t)
        return false;
    return true;
}*/
ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF/k<i) break;

            k=k*i;
            if(j!=2)
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {
         ll q=sqrt(s1[i]);
        if(q*q!=s1[i])
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;
bool check(ll t)
{
    ll q=sqrt(t);
    if(q*q==t||(q+1)*(q+1)==t||(q-1)*(q-1)==t)
        return false;
    return true;
}
ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i*i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF<k*i) break;
            k=k*i;
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {

        if(check(s1[i]))
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;
bool check(ll t)
{
    ll q=sqrt(t);
    if(q*q==t||(q+1)*(q+1)==t||(q-1)*(q-1)==t)
        return false;
    return true;
}
ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i*i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF<k*i) break;
            k=k*i;
            if(j!=2)
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {

        if(check(s1[i]))
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define INF 1e18
using namespace std;
ll l,r;
bool check(ll t)
{
    ll q=sqrt(t);
    if(q*q==t||(q+1)*(q+1)==t||(q-1)*(q-1)==t)
        return false;
    return true;
}
ll add()
{
    ll lr=2,rr=1e9+100;
    ll la=-1;

    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>=l)
        {
            rr=mid-1;
            la=mid;
        }
        else lr=mid+1;
    }
    lr=2,rr=1e9+100;
    ll ar=-1;
    //cout<<la<<endl;
    while(lr<=rr)
    {
        ll mid=(lr+rr)/2;
        if(mid*mid>r)
        {
            rr=mid-1;
            ar=mid;
        }
        else
        {
            lr=mid+1;
        }
    }
    return ar-la;
}
int main()
{
    int q;
    vector<ll>s1;
    vector<ll>s2;
    s1.clear();
    s2.clear();
    for(int i=2;i<=1e6;i++)
    {
        ll k=i;///��Ϊp��ֵ�Ǵ���1������pΪ���ڵ���3
        for(int j=2;j<=64;j++)
        {
            if(INF/k<i) break;
            k=k*i;
            if(j!=2)
            s1.push_back(k);
        }
    }
    sort(s1.begin(),s1.end());//����һ������
    s1.erase(unique(s1.begin(),s1.end()),s1.end());
    int si=s1.size();
    for(int i=0;i<s1.size();i++)
    {

        if(check(s1[i]))
        {
            s2.push_back(s1[i]);
        }
    }
    while(~scanf("%d",&q))
    {
       for(int i=1;i<=q;i++)
       {
           scanf("%I64d%I64d",&l,&r);
           ll ans=0;
           if(l<=1) ans++;
           ans+=upper_bound(s2.begin(),s2.end(),r)-lower_bound(s2.begin(),s2.end(),l);
          // cout<<ans<<endl;
           ans+=add();
           printf("%I64d\n",ans);
       }
    }

    return 0;
}


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

const long long MX = 1e18;
long long n, a[1014884];
//vector<long long> a;

long long cnt(long long k) {
    if (k == 0) return 0;
    return (long long)(upper_bound(a, a+n, k) - a) + (long long)ceil(sqrt(k));
}

int main () {

    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = ceil(sqrt(j));
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

#define FOR(i, a, b) for(int i=a; i<=b; ++i)
#define For(i, a, b) for(int i=a; i<b; ++i)
#define FORD(i, a, b) for(int i=a; i>=b; --i)
#define ll long long
#define db double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Fill(s, a) memset(s, a, sizeof(s))

unsigned ll l, r, a[1050001];
int q, n;
const ll INF = 1e18;

void init()
{
    for(ll i = 2; i*i*i <= INF; i++)
    {
        for(ll j=i; j <= INF/(i*i); j *= (i*i))
        {
            long long tmp = sqrt(j*i*i);
            if(tmp*tmp != j*i*i)
                a[n++] = j*i*i;
        }
    }
}

ll calc(ll x)
{
    if (x == 0)
        return 0;
    return (ll)sqrt(x) + (ll)(upper_bound(a, a+n, x) - a);
}

int main()
{

    init();
    sort(a+1, a+n);
    n = unique(a, a+n)-a;
    cin >> q;
    while (q--)
    {
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", calc(r) - calc(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
vector<long long> a;

long long cnt(long long x) {
    if (x == 0) return 0;
    return sqrt(x) + upper_bound(a.begin(), a.end(), x) - a.begin();
}

int main () {
    //freopen("test01.in", "r", stdin);
    //freopen("", "w", stdout);
    for (long long i = 2; i*i*i <= MX; i++) {
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(j);
            if (k*k != j)
                a.push_back(j);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
long long n, a[1014884];
//vector<long long> a;

long long cnt(long long k) {
    if (k == 0) return 0;
    return (long long)floor(sqrt(k)) + (long long)(upper_bound(a, a+n, k) - a);
}

int main () {

    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = ceil(sqrt(j));
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
long long n, a[1014884];
//vector<long long> a;

long long cnt(long long k) {
    if (k == 0) return 0;
    return (long long)floor(sqrt(k)) + (long long)(upper_bound(a, a+n, k) - a);
}

int main () {

    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = (long long)floor(sqrt(j));
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
long long n, a[1014884];
//vector<long long> a;

long long can_bac_2(long long x) {
    long long y = sqrt(x);
    for (long long i = y-1; i <= y+1; i++)
        if (i*i == x) return i;
    return 0;
}

long long cnt(long long k) {
    if (k == 0) return 0;
    return sqrt(double(k)) + (long long)(upper_bound(a, a+n, k) - a);
}

int main () {

    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(double(j));
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
}


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

const long long MX = 1e18;
long long n, a[1014884];

long long cnt(long long k) {
    if (k == 0) return 0;
    return (long long)(upper_bound(a, a+n, k) - a) + (long long)floor(sqrt(k));
}

int main () {
    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = floor(sqrt(j));
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    //scanf("%d", &q);
    cin >> q;
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
vector<long long> a;

long long cnt(long long x) {
    if (x == 0) return 0;
    return upper_bound(a.begin(), a.end(), x) - a.begin() + sqrt(x);
}

int main () {
    //freopen("test01.in", "r", stdin);
    //freopen("", "w", stdout);
    for (long long i = 2; i*i*i <= MX; i++) {
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(j);
            if (k*k != j)
                a.push_back(j);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        cout << cnt(l-1) << '\n' << cnt(r) << '\n';
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
vector<long long> a;

long long cnt(long long x) {
    if (x == 0) return 0;
    return sqrt(x) + (long long)(upper_bound(a.begin(), a.end(), x) - a.begin());
}

int main () {
    //freopen("test01.in", "r", stdin);
    //freopen("", "w", stdout);
    for (long long i = 2; i*i*i <= MX; i++) {
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(j);
            if (k*k != j)
                a.push_back(j);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
vector<long long> a;

long long cnt(long long x) {
    if (x == 0) return 0;
    return upper_bound(a.begin(), a.end(), x) - a.begin() + sqrt(x);
}

int main () {
    //freopen("test01.in", "r", stdin);
    //freopen("", "w", stdout);
    for (long long i = 2; i*i*i <= MX; i++) {
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(j);
            if (k*k != j)
                a.push_back(j);
        }
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


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

const long long MX = 1e18;
long long n, a[1014884];
//vector<long long> a;

long long cnt(long long x) {
    if (x == 0) return 0;
    return sqrt(x) + (long long)(upper_bound(a, a+n, x) - a);
}

int main () {
    //freopen("test01.in", "r", stdin);
    //freopen("test01.out", "w", stdout);
    for (long long i = 2; i*i*i <= MX; i++)
        for (long long j = i*i; j <= MX/i; ) {
            j *= i;
            long long k = sqrt(j);
            if (k*k != j)
                a[n++] = j;
        }
    sort(a, a+n);
    n = unique(a, a+n) - a;
    int q;
    scanf("%d", &q);
    while (q--) {
        long long l, r;
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", cnt(r) - cnt(l-1));
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int s=1e7;

int64_t arr[s],high=2e18,mid=1e12,h=1e18,k=1e6+1;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int64_t i,siz=1,num,curr=0;
    arr[0]=1;
    for(i=2;i<k;i++)
    {
        num=i;
        while(1)
        {
            if(num>mid && num>(high/i))
                    break;
            num*=i;
            if(num>h){break;}
            arr[siz]=num;
            siz++;
        }
    }
    sort(arr,arr+siz);
    for(i=1;i<siz;i++)
    {
        if(arr[i]!=arr[curr])
        {
            curr++; arr[curr]=arr[i];
        }
    }
    siz=curr;
    int q;
    int64_t l,r,a,b,ans,temp;
    cin>>q;
    while(q--)
    {
        cin>>l>>r;
        a=lower_bound(arr,arr+siz,l)-arr;
        b=lower_bound(arr,arr+siz,r)-arr;
        if(arr[b]>r){b--;}
        ans=max((int64_t)0,b-a+1);
        a=sqrt(l);
        if((a*a)!=l){a++;}
        a=max(a,k);
        b=sqrt(r);
        temp=b-a+1;
        if(temp>0)
        {
            ans+=temp;
            a=lower_bound(arr,arr+siz,a)-arr;
            r=lower_bound(arr,arr+siz,b)-arr;
            if(arr[r]>b){r--;}
            ans-=max((int64_t)0,r-a+1);
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
#define Max 1000005
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define getchar gc
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}

ll t,l,r,size,miu[Max],prime[Max];
bool vis[Max];

inline bool check(ll num,ll xx,ll y){
	long double ans=1,x=xx;
	while(y){
		if(x<=0)return false;
		if(ans>num/x)return false;
		if(y&1){
			ans=ans*x;
		}
		x=x*x;
		y>>=1;
	}
	if(ans>num)return false;else return true;
}

inline ll work(ll num,ll k){
	int ans=ceil(pow(num,1.0/k));
// 	while(check(num,ans,k))ans++;
	if(!check(num,ans,k))ans--;
	return ans;
}

inline ll calc(ll x){
	if(x<=0)return 0;
	int ans=1;
	for(int i=2;i<=64;i++){
		int num=work(x,i);
		ans=ans-miu[i]*(num-1);
//		cout<<num-1<<endl;
	}
	return ans;
}

signed main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	miu[1]=1;
	for(int i=2;i<=100;i++){
		if(!vis[i]){
			prime[++size]=i;
			miu[i]=-1;
		}
		for(int j=1;j<=size;j++){
			int k=prime[j]*i;
			if(k>100)break;
			vis[k]=true;
			if(i%prime[j]==0){
				miu[k]=0;
				break;
			}else{
				miu[k]=-miu[i];
			}
		}
	}
	t=read();
	while(t--){
		l=read();r=read();
		writeln(calc(r)-calc(l-1));
	}
	return 0;
}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT ans=1) {

	for(; b; b>>=1, a=a*a) if(b&1) ans=ans*a;

	return ans;

}

#define NN 110

int nn, vst[NN];

INT p[NN];

void init() {

	for(int i=2; i<NN; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<NN; j+=i) vst[j]=1;

	}

}

INT fff(INT n, INT ff) {

	INT xx=max((INT)pow(1.*n, 1./ff)-2LL, 0LL);

	while(power(xx, ff)<=n) xx++;

	return xx-2LL;

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT yy=max((INT)(log(xx)/log(2))-2LL, 0LL);

	while((1LL<<yy)<=xx) yy++;

	INT mmx=max(yy-1LL, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	if(2*3*5<=mmx) ans+=fff(xx, 30);

	if(2*3*7<=mmx) ans+=fff(xx, 42);

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT ans=1) {

	for(; b; b>>=1, a=a*a) if(b&1) ans=ans*a;

	return ans;

}

#define NN 110

int nn, vst[NN];

INT p[NN];

void init() {

	for(int i=2; i<NN; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<NN; j+=i) vst[j]=1;

	}

}

INT fff(INT n, INT ff) {

	INT xx=max((INT)pow(1.*n, 1./ff)-4LL, 0LL);

	while(power(xx, ff)<=n) xx++;

	xx-=2;

	return xx;

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT yy=max((INT)(log(xx)/log(2))-3LL, 0LL);

	while((1LL<<yy)<=xx) yy++;

	INT mmx=max(yy-1LL, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) {

			for(int k=j+1; k<nn; k++) if(p[i]*p[j]*p[k]<=mmx) {

				ans+=fff(xx, p[i]*p[j]*p[k]);

			}

		}

	}

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

INT power(INT a, INT b, INT ans=1) {

	for(; b; b>>=1, a=a*a) if(b&1) ans=ans*a;

	return ans;

}

#define NN 110

int nn, vst[NN];

INT p[NN];

void init() {

	for(int i=2; i<NN; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<NN; j+=i) vst[j]=1;

	}

}

INT fff(INT n, INT ff) {

	INT xx=max((INT)pow(1.*n, 1./ff)-2LL, 0LL);

	while(power(xx, ff)<=n) xx++;

	return xx-2LL;

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT yy=max((INT)(log(xx)/log(2))-2LL, 0LL);

	while((1LL<<yy)<=xx) yy++;

	INT mmx=max(yy-1LL, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) {

			for(int k=j+1; k<nn; k++) if(p[i]*p[j]*p[k]<=mmx) {

				ans+=fff(xx, p[i]*p[j]*p[k]);

			}

		}

	}

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

long double power(long double a, INT b, long double ans=1) {

	for(; b; b>>=1, a=a*a) if(b&1) ans=ans*a;

	return ans;

}

#define NN 110

int nn, vst[NN];

INT p[NN];

void init() {

	for(int i=2; i<NN; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i*i; j<NN; j+=i) vst[j]=1;

	}

}

INT fff(INT n, INT ff) {

	INT xx=(INT)pow(n, 1./ff);

	while(power((long double) xx, ff)<=n) xx++;

	return max(xx-2, 0LL);

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT mmx=63;

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	if(2*3*5<=mmx) ans+=fff(xx, 30);

	if(2*3*7<=mmx) ans+=fff(xx, 42);

	return ans;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1) + (l==1));

	}

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100

int nn, p[NN];

int vst[NN];

void init() {

	for(int i=2; i<64; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<64; j+=i) vst[j]=1;

	}

}

INT fff(INT n, int ff) {

	return max((INT)(pow(1.*n, 1./ff)+eps)-1, 0LL);

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT mmx=(int)(log(xx)/log(2)+eps);

	smax(mmx, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) {

			for(int k=j+1; k<nn; k++) if(p[i]*p[j]*p[k]<=mmx) {

				ans+=fff(xx, p[i]*p[j]*p[k]);

			}

		}

	}

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n;

	INT l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define MOD 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<typename T> inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T, class T1>inline void gn(T &x, T1 &y) {gn(x); gn(y);}

template<class T, class T1, class T2>inline void gn(T &x, T1 &y, T2 &z) {gn(x); gn(y); gn(z);}

template<typename T> inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

template<typename T> inline void println(T x) {print(x), putchar('\n');}

template<typename T> inline void printsp(T x) {print(x), putchar(' ');}

template<class T, class T1> inline void print(T x, T1 y) {printsp(x), println(y);}

template<class T, class T1, class T2> inline void print(T x, T1 y, T2 z) {printsp(x), printsp(y), println(z);}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

INT calc(INT n, int k){

	INT ans=(INT)pow(n, 1.0/k);

	INT val=1;

	for(int i=0; i<k; i++){

		if(val>n/(ans+1)) return ans;

		val*=(ans+1);

	}

	return ans+1;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int cnt=0;

	int p[20];

	for(int i=2; i<=60; i++){

		int ok=1;

		for(int j=2; j<i; j++) if(i%j==0) ok=0;

		if(ok) p[cnt++]=i;

	}

	int nn=0;

	int val[100], sgn[100];

	for(int i=1; i<1<<cnt; i++){

		int m=1;

		for(int j=0; j<cnt; j++) if(bit(i, j)) m=min(m*p[j], 100);

		if(m<=60) val[nn]=m, sgn[nn++]=((bpt(i)&1) ? 1 : -1);

	}

	int n;

	INT L, R;

	for(gn(n); n--; ){

		gn(L, R);

		INT ans=0;

		if(L==1) L++, ans++;

		for(int i=0; i<nn; i++){

			ans+=calc(R, val[i])*sgn[i]-calc(L-1, val[i])*sgn[i];

		}

		println(ans);

	}

	return 0;

}


#include<bits/stdc++.h>

#define x first

#define y second

#define eps 1e-7

#define pb push_back

#define inf 0x3f3f3f3f

#define mod 1000000007

#define sq(x) ((x)*(x))

#define cb(x) ((x)*(x)*(x))

#define bit(x, y) (((x)>>(y))&1)

#define bctz(x) (__builtin_ctz(x))

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzl(x))

#define bctzl(x) (__builtin_ctzl(x))

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define pi 3.1415926535897932384626433832795

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

using namespace std;

typedef double DO;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

template<typename T, typename U> inline void smin(T &a, U b) {if(a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if(a<b) a=b;}

template <class T> inline void gn(T &x) {char c, sg=0; while(c=getchar(), (c>'9' || c<'0') && c!='-'); for((c=='-' ? sg=1, c=getchar() : 0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0'; if(sg) x=-x;}

template <class T1, class T2> inline void gn(T1 &x1, T2 &x2) {gn(x1), gn(x2);}

template <class T1, class T2, class T3> inline void gn(T1 &x1, T2 &x2, T3 &x3) {gn(x1, x2), gn(x3);}

template <class T1, class T2, class T3, class T4> inline void gn(T1 &x1, T2 &x2, T3 &x3, T4 &x4) {gn(x1, x2), gn(x3, x4);}

template <class T> inline void print(T x) {if(x<0) {putchar('-'); return print(-x);} if(x<10) {putchar('0'+x); return ;} print(x/10); putchar(x%10+'0');}

template <class T> inline void println(T x) {print(x); putchar('\n');}

template <class T> inline void printsp(T x) {print(x); putchar(' ');}

template <class T1, class T2> inline void print(T1 x1, T2 x2) {printsp(x1), println(x2);}

template <class T1, class T2, class T3> inline void print(T1 x1, T2 x2, T3 x3) {printsp(x1), printsp(x2), println(x3);}

template <class T1, class T2, class T3, class T4> inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {printsp(x1), printsp(x2), printsp(x3), println(x4);}

int power(int a, int b, int m, int ans=1) {

	for(; b; b>>=1, a=1LL*a*a%m) if(b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 100

int nn, p[NN];

int vst[NN];

INT f[NN];

#define MM 300010

int m;

int x[MM];

void init() {

	for(int i=2; i<64; i++) if(vst[i]==0) {

		p[nn++]=i;

		for(int j=i+i; j<64; j+=i) vst[j]=1;

	}

}

INT fff(INT n, int ff) {

	return max((INT)(pow(1.*n, 1./ff)+eps)-1, 0LL);

}

INT calc(INT xx) {

	if(xx==0) return 0;

	if(xx==1) return 1;

	INT mmx=(int)(log(xx)/log(2)+eps);

	smax(mmx, 0LL);

	INT ans=0;

	for(int i=0; i<nn; i++) if(p[i]<=mmx) {

		ans+=fff(xx, p[i]);

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) if(p[i]*p[j]<=mmx) {

			ans-=fff(xx, p[i]*p[j]);

		}

	}

	for(int i=0; i<nn; i++) {

		for(int j=i+1; j<nn; j++) {

			for(int k=j+1; k<nn; k++) if(p[i]*p[j]*p[k]<=mmx) {

				ans+=fff(xx, p[i]*p[j]*p[k]);

			}

		}

	}

	return ans+1;

}

int main() {

#ifndef	ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	init();

	int n, l, r;

	gn(n);

	while(n--) {

		gn(l, r);

		println(calc(r)-calc(l-1));

	}

}