#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

vector<int> primes;
int primes_c;

void doprime()
{
    primes.push_back(2);
    primes.push_back(3);
    primes.push_back(5);
    primes_c = 3;
    for(int i = 7; i <= 1000; i+=2)
    {
        bool ok = true;
        int s = sqrt(i);
        for(int j = 0; j < primes_c && primes[j] <= s; j++)
        {
            if (i % primes[j] == 0)
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            primes_c++;
            primes.push_back(i);
        }
    }
}

vector<unsigned long long> qbs(1000000);

void initqbs()
{
    for(int i = 1; i <= 1000000; i++)
    {
        qbs[i] = i;
        qbs[i] *= i;
        qbs[i] *= i;
    }
}

int main()
{
    initqbs();

    doprime();
   // cout << primes_c << endl;
    int n;
    cin >> n;
    while(n--)
    {
        int a,b;
        cin >> a >> b;
        int c = a,d = b;
        if ((a == b) && (b == 1))
        {
            cout << "Yes" << endl;
            continue;
        }
        if ((a == b*b) || (b == a*a))
        {
            cout << "Yes" << endl;
            continue;
        }
        unsigned long long res = a;
        res *= b;
        int sq = lower_bound(qbs.begin(), qbs.end(),res) - qbs.begin();
        unsigned long long w = sq;
        w*=sq;
        w*=sq;
        if (w != res)
        {
            cout << "No" << endl;
            continue;
        }
        int j = 0;
        bool ok = true;
        a /= sq;
        b /= sq;
        if (!ok) continue;
        int a1 = a, b1 = b;
        if ((a1*a1*b1 == c) && (a1*b1*b1 == d))
        {
            cout << "Yes" << endl;
            continue;
        }
        else
        {
            cout << "No" << endl;
            continue;
        }
    }
    return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;

vector<int> primes;
int primes_c;

void doprime()
{
    primes.push_back(2);
    primes.push_back(3);
    primes.push_back(5);
    primes_c = 3;
    for(int i = 7; i <= 1000; i+=2)
    {
        bool ok = true;
        int s = sqrt(i);
        for(int j = 0; j < primes_c && primes[j] <= s; j++)
        {
            if (i % primes[j] == 0)
            {
                ok = false;
                break;
            }
        }
        if (ok)
        {
            primes_c++;
            primes.push_back(i);
        }
    }
}

vector<unsigned long long> qbs(1000000);

void initqbs()
{
    for(int i = 1; i <= 1000000; i++)
    {
        qbs[i] = i;
        qbs[i] *= i;
        qbs[i] *= i;
    }
}

int main()
{
    initqbs();

  //  doprime();
   // cout << primes_c << endl;
    int n;
    cin >> n;
    while(n--)
    {
        int a,b;
        cin >> a >> b;
        int c = a,d = b;
        if ((a == b) && (b == 1))
        {
            cout << "Yes" << endl;
            continue;
        }
        if ((a == b*b) || (b == a*a))
        {
            cout << "Yes" << endl;
            continue;
        }
        unsigned long long res = a;
        res *= b;
        int sq = find(qbs.begin(), qbs.end(),res) - qbs.begin();
        unsigned long long w = sq;
        w*=sq;
        w*=sq;
        if (w != res)
        {
            cout << "No" << endl;
            continue;
        }
        int j = 0;
        bool ok = true;
        a /= sq;
        b /= sq;
        if (!ok) continue;
        int a1 = a, b1 = b;
        if ((a1*a1*b1 == c) && (a1*b1*b1 == d))
        {
            cout << "Yes" << endl;
            continue;
        }
        else
        {
            cout << "No" << endl;
            continue;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1500
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
ll mul, res;
ll mod(ll x, ll p){
	x -= x/p*p;
	return x<0?x+p:x ;
}
ll my_pow(ll x, ll y, ll p){
	mul = mod(x, p);
	res = 1;
	while(y){
		if(y&1) res*=mul, res = mod(res, p);
		mul*=mul, mul = mod(mul, p);
		y>>=1;
	}
	return res;
}
bool is_prm_func(ll x, ll num){
	return my_pow(num, x-1, x) == 1;
}
int haha[]{2, 3, 7, 61, 24251};
bool hahaha;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = hahaha = false;
		RII(a,b);
		if(a<b) swap(a,b);
		for(int i=0;i<5;++i){
			if( a > prm.back() && is_prm_func(a, haha[i]) ){
				hahaha = true;
				break;
			}
			else if( b > prm.back() && is_prm_func(b, haha[i]) ){
				hahaha = true;
				break;
			}
		}
		if(hahaha){
			puts("No");
			continue;
		}
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 2000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	scanf("%d",&T);
	while(T--){
		con = false;
		scanf("%d%d",&a,&b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a>1000&&a==b*b){
			puts("Yes");
		}
		else if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 31623
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
ll mul, res;
ll mod(ll x, ll p){
	x -= x/p*p;
	return x<0?x+p:x ;
}
ll my_pow(ll x, ll y, ll p){
	mul = mod(x, p);
	res = 1;
	while(y){
		if(y&1) res*=mul, res = mod(res, p);
		mul*=mul, mul = mod(mul, p);
		y>>=1;
	}
	return res;
}
bool is_prm_func(ll x, ll num){
	return my_pow(num, x-1, x) == 1;
}
int haha[]{2, 3, 7, 61, 24251};
bool hahaha;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = hahaha = false;
		RII(a,b);
		for(int i=0;i<5;++i){
			if( a > prm.back() && is_prm_func(a, haha[i]) ){
				hahaha = true;
				break;
			}
			else if( b > prm.back() && is_prm_func(b, haha[i]) ){
				hahaha = true;
				break;
			}
		}
		if(hahaha){
			puts("No");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 500
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
		}
		else if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 31623
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
ll mul, res;
ll mod(ll x, ll p){
	x -= x/p*p;
	return x<0?x+p:x ;
}
ll my_pow(ll x, ll y, ll p){
	mul = mod(x, p);
	res = 1;
	while(y){
		if(y&1) res*=mul, res = mod(res, p);
		mul*=mul, mul = mod(mul, p);
		y>>=1;
	}
	return res;
}
bool is_prm_func(ll x, ll num){
	return my_pow(num, x-1, x) == 1;
}
int haha[]{2, 3, 7, 61, 24251};
bool hahaha;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = hahaha = false;
		RII(a,b);
		if(a<b) swap(a,b);
		for(int i=0;i<5;++i){
			if( a > prm.back() && is_prm_func(a, haha[i]) ){
				hahaha = true;
				break;
			}
			else if( b > prm.back() && is_prm_func(b, haha[i]) ){
				hahaha = true;
				break;
			}
		}
		if(hahaha){
			puts("No");
			continue;
		}
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 100000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool isprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) isprm[i] = true;
	for(int i=2;i<=N;++i) if(isprm[i]){
		for(int j=i+i;j<=N;j+=i){
			isprm[j] = false;
		}
	}
	for(int i=2;i<=N;++i) if(isprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		for(int i=0;i<SZ(prm);++i){
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)%3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 35000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
map<int,bool> mp;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 500
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i), mp[i] = true;
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(mp[a]&&mp[b]){
			puts("No");
			continue;
		}
		if(mp[b]&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con ;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a>1000&&a==b*b){
			puts("Yes");
		}
		else if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a>1000&&a==b*b){
			puts("Yes");
		}
		else if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 40000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool isprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) isprm[i] = true;
	for(int i=2;i<=N;++i) if(isprm[i]){
		for(int j=i+i;j<=N;j+=i){
			isprm[j] = false;
		}
	}
	for(int i=2;i<=N;++i) if(isprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)%3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 1000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i*i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a>1000&&a==b*b){
			puts("Yes");
		}
		else if(a!=1||b!=1) puts("NoHI");
		else{
			puts("Yes");
		}
	}
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 31623
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		for(int i=0;i<SZ(prm)&&prm[i]<=a&&prm[i]<=b;++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


/* By IPlocker*/
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG
#define INF 0x3f3f3f3f
#define INF16 16000000000000000LL
#define INF18 1000000000000000000LL
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define mod9 (int)(1e7 + 9)
#define mod7 (int)(1e7 + 7)
#define eps 1e-9
#define mse(x , y) memset(x , y , sizeof(x))
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define IOS do { ios::sync_with_stdio(0);cin.tie(0); } while (0)
typedef pair< int , int > pii;
typedef long long ll;

template < typename Iter >
ostream& _out(ostream& s , Iter a , Iter b){
    for(auto it = a; it != b; it++)
        s << (it == a ? "" : " ") << *it;
    return s;
}

template < typename A , typename B >
ostream& operator << (ostream &s , pair< A , B > &p){ return s << "(" << p.F << " , " << p.S << ")"; }
template < typename T >
ostream& operator << (ostream &s , vector< T > &v){ return _out(s , ALL(v)); }

inline ll rit(){
    int key = 1;
    char c = getchar();
    while(!isdigit(c)){
        if(c == '-') key = -1;
        c = getchar();
    }

    ll x = 0;
    while(isdigit(c)){
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * key;
}

int __ = 1;

/*********default*********/

void init(){
}

void read(){
}

void solve(){
}

int bad[1010000];
int good[110][110];

int main(){
    vector<int> v;

    for(int i = 2; i <= 1000; i++) {
        if(bad[i]) continue;
        v.push_back(i);
        for(int j = i * 2; j <= 1000; j += i) {
            bad[j] = 1;
        }
    }

    good[0][0] = 1;
    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            if(good[i][j]) {
                good[i + 1][j + 2] = 1;
                good[i + 2][j + 1] = 1;
            }
        }
    }

    int t;
    scanf("%d", &t);
    while(t--) {
        long long a, b;
        scanf("%lld%lld", &a, &b);
        int ok = 1;
        for(int i = 0; i < v.size(); i++) {
            if(a % v[i] == 0) {
                int cnt1 = 0, cnt2 = 0;
                long long ret = a;
                while(ret % v[i] == 0) {
                    cnt1++;
                    ret /= v[i];
                }

                ret = b;
                while(ret % v[i] == 0) {
                    cnt2++;
                    ret /= v[i];
                }

                if(good[cnt1][cnt2]) {
                    for(int j = 0; j < cnt1; j++)
                        a /= v[i];
                    for(int j = 0; j < cnt2; j++)
                        b /= v[i];
                }
            }
        }

        if(a == 1 && b == 1) puts("Yes");
        else puts("No");
    }
    return 0;
}


#include<bits/stdc++.h>
#define RI(x) x = rit()
#define RII(a,b) a = rit(), b = rit()
#define RIII(a,b,c) a = rit(), b = rit(), c = rit()
#define REP(I, N) for(int I=0;I<int(N);I++)
#define REPP(I, N) for(int I=1;I<=int(N);I++)
#define ll long long
#define SZ(x) (int)(x).size()
#define F first
#define S second
#define PB(x) push_back(x)
#define N 10000
#define modn 1000000007
inline int rit(){
    int f=0,key=1;
    char ch;
    do{
        ch = getchar();
        if(ch=='-') key=-1;;
    }while(ch<'0'||ch>'9');
    do{
        f = f*10+ch-'0';
        ch = getchar();
    }while(ch>='0'&&ch<='9');
    return f*key;
}
using namespace std;
typedef pair<int,int> P;
bool nprm[N+5];
vector<int> prm;
int cnta, cntb;
void Build_Prime(){
	for(int i=2;i<=N;++i) if(!nprm[i]){
		for(int j=i+i;j<=N;j+=i){
			nprm[j] = true;
		}
	}
	for(int i=2;i<=N;++i) if(!nprm[i]) prm.PB(i);
}
int T,a,b;
bool con;
int main(void){
	Build_Prime();
	RI(T);
	while(T--){
		con = false;
		RII(a,b);
		if(a<b) swap(a,b);
		if(a>1000&&a==b*b){
			puts("Yes");
			continue;
		}
		for(int i=0;i<SZ(prm);++i){
			if(a==1||b==1) break;
			cnta = cntb = 0;
			while(a%prm[i]==0) ++cnta, a/=prm[i];
			while(b%prm[i]==0) ++cntb, b/=prm[i];
			if(cnta<cntb) swap(cnta, cntb);
			if(!cnta&&!cntb) continue;
			if(!cntb){
				puts("No");
				con = true;
				break;
			}
			if(cnta>cntb*2){
				puts("No");
				con = true;
				break;
			}
			if( (cnta+cntb)-(cnta+cntb)/3*3 ){
				puts("No");
				con = true;
				break;
			}
		}
		if(con) continue;
		if(a!=1||b!=1) puts("No");
		else{
			puts("Yes");
		}
	}
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if((x+y)%3!=0||(x+y)/3<abs(x-y)||(((x+y)/3)&1)!=(abs(x-y)&1)){flag = false;break;}

		}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	int i=0;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(++i<=n){

		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false;break;}
		}
		ll croot =(ll)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&a == b&&(a ==pow(croot,3)||a==pow(croot+1,3)||a== pow(croot-1,3))){cout<<"Yes"<<endl;continue;}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(y>100000||x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>200000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){printf("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int i=0;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(++i<=n){

		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false;break;}
		}
		ll croot =(ll)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&a == b&&(a ==pow(croot,3))){cout<<"Yes"<<endl;continue;}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if((x+y)%3!=0||(x+y)/3<abs(x-y)||(((x+y)/3)&1)!=(abs(x-y)&1)){flag = false;break;}

		}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
inline void writestr( const string &s ) {
	 for (int i = 0; i < (int)s.size(); ++i) putchar(s[i]);
}

int main(){

	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>1000000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){writestr("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)writestr("Yes\n");
		else writestr("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	int i=0;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(++i<=n){

		ll a, b,x ,y;
		cin>>a>>b;
		if(i==3197)cout<<b<<" "<<b<<endl;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false;break;}
		}
		ll croot =(ll)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&x == y&&(y ==pow(croot,3)||y==pow(croot+1,3)||y == pow(croot-1,3))){cout<<"Yes"<<endl;continue;}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(y>100000||x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	scanf("%d",&n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		scanf("%d%d",&a,&b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>200000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){printf("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if((x+y)%3!=0||(x+y)/3<abs(x-y)||(((x+y)/3)&1)!=(abs(x-y)&1)){flag = false;break;}

		}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(y>100000||x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			//cout<<x<<" "<<y<<endl;
			if((x+y)%3!=0||(x+y)/3<abs(x-y)||(((x+y)/3)&1)!=(abs(x-y)&1)){flag = false;break;}

		}
		x = __gcd(a,b);
		y = __gcd(x,a);
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
inline void writestr( const string &s ) {
	 for (int i = 0; i < (int)s.size(); ++i) putchar_unlocked(s[i]);
}

int main(){
	freopen("input","r",stdin);
	freopen("output","w",stdout);
	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>1000000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){writestr("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)writestr("Yes\n");
		else writestr("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
inline void writestr( const string &s ) {
	 for (int i = 0; i < (int)s.size(); ++i) putchar(s[i]);
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){writestr("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)writestr("Yes\n");
		else writestr("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	scanf("%d",&n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		scanf("%d%d",&a,&b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>200000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){printf("Yes\n");continue;}
		}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){

	int n,a,b,x,y,croot;
	scanf("%d",&n);
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		scanf("%d%d",&a,&b);
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		croot =(int)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&a==b&&a==pow(croot,3)){printf("Yes\n");continue;}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(n--){
		ll a, b,x ,y;
		cin>>a>>b;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false;break;}
		}
		ll croot =(ll)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&x == y&&(y ==pow(croot,3)||y==pow(croot+1,3)||y == pow(croot-1,3))){cout<<"Yes"<<endl;continue;}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(y>100000||x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main(){

	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		croot =(int)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&a==b&&a==pow(croot,3)){puts("Yes");continue;}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)puts("Yes");
		else puts("No");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	int i=0;
	vector<int> pr = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
	while(++i<=n){

		ll a, b,x ,y;
		cin>>a>>b;
		if(i==3197)cout<<a<<" "<<b<<endl;
		bool flag =true;
		for(int i=0;i<pr.size();i++){
			x =0; y =0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false;break;}
		}
		ll croot =(ll)(pow((ld)a,1.0/3.0)+0.5);
		if(flag&&x == y&&(y ==pow(croot,3)||y==pow(croot+1,3)||y == pow(croot-1,3))){cout<<"Yes"<<endl;continue;}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(y>100000||x>100000||a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	scanf("%d",&n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
	    fastscan(a);
	    fastscan(b);
		//scanf("%d%d",&a,&b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>200000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){printf("Yes\n");continue;}
		}
		x = __gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
inline void writestr( const string &s ) {
	 for (int i = 0; i < (int)s.size(); ++i) putc_unlocked(s[i],stdout);
}

int main(){

	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>1000000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){writestr("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)writestr("Yes\n");
		else writestr("No\n");
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

inline void fastscan(int &x){
	register int c;
	x =0;
	c=getchar();
	for(;(c>47 && c<58);c=getchar_unlocked())
		x = (x<<1) + (x<<3) +c -48;
}
inline int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
inline void writestr( const string &s ) {
	 for (int i = 0; i < (int)s.size(); ++i) putchar_unlocked(s[i]);
}

int main(){
	int n,a,b,x,y,croot;
	bool flag;
	fastscan(n);
	int pr[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
	while(n--){
		fastscan(a);
		fastscan(b);
		flag =true;
		for(int i=0;i<18;i++){
			x =0;y=0;
			while(a%pr[i]==0)a/=pr[i],x++;
			while(b%pr[i]==0)b/=pr[i],y++;
			if(((x+y)%3!=0)||((x+y)/3<abs(x-y))){flag = false; break;}
		}
		if(flag&&a==b&&a>1000000){
			croot =(int)(pow((ld)a,1.0/3.0)+0.5);
			if(a==pow(croot,3)){writestr("Yes\n");continue;}
		}
		x = gcd(a,b);
		y = a/x;
		x /= y;
		if(a!=y*y*x||b!=x*x*y)flag =false;
		if(flag)writestr("Yes\n");
		else writestr("No\n");
	}
	return 0;
}


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

int gcd(int x, int y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6;
map<LL, int>mp;
int main() {
    for (int i = 1; i < maxn; i++)
        mp[i * i * i * 1ll] = i;
    int n;
    cin>>n;
    while (n--) {
        int a, b;
        cin>>a>>b;
        LL p = a * b * 1ll;
        if (mp[p] <= gcd(a, b) && mp[p]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

int gcd(int x, int y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6;
map<LL, int>mp;
int main() {
    for (int i = 1; i < maxn; i++)
        mp[i * i * i] = i;
    int n;
    cin>>n;
    while (n--) {
        int a, b;
        cin>>a>>b;
        LL p = a * b * 1ll;
        if (mp[p] <= gcd(a, b) && mp[p]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

LL gcd(LL x, LL y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6 + 10;
map<LL, LL>mp;
int main() {
    for (LL i = 1; i < maxn; i++)
        mp[i * i * i] = i;
    int n;
    cin>>n;
    while (n--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL p = a * b;
        if (!mp[p]) {printf("No\n"); continue;}
        if (a % mp[p] || b % mp[p]) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}


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

LL gcd(LL x, LL y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6 + 10;
map<LL, LL>mp;
int main() {
    for (LL i = 1; i < maxn; i++)
        mp[i * i * i] = i;
    int n;
    cin>>n;
    while (n--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL p = a * b;
        if (!mp[p]) {printf("No\n"); continue;}
        if (mp[p] <= a && mp[p] <= b) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

int gcd(int x, int y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6;
map<LL, int>mp;
int main() {
    for (int i = 1; i < maxn; i++)
        mp[(i * 1ll) * (i * 1ll) * (i * 1ll)] = i;
    int n;
    cin>>n;
    while (n--) {
        int a, b;
        cin>>a>>b;
        LL p = (a * 1ll) * (b * 1ll);
        if (mp[p] <= gcd(a, b) && mp[p]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

LL gcd(LL x, LL y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6 + 10;
map<LL, LL>mp;
int main() {
    for (LL i = 1; i < maxn; i++)
        mp[i * i * i] = i;
    int n;
    cin>>n;
    while (n--) {
        LL a, b;
        scanf("%I64d%I64d", &a, &b);
        LL p = a * b;
        if (!mp[p]) {printf("No\n"); continue}
        if (mp[p] <= gcd(a, b)) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

int gcd(int x, int y) {
    return x % y ? gcd(y, x % y) : y;
}
const int maxn = 1e6;
map<LL, int>mp;
int main() {
    for (int i = 1; i < maxn; i++)
        mp[i * i * i] = i;
    int n;
    cin>>n;
    while (n--) {
        int a, b;
        cin>>a>>b;
        LL p = a * b;
        if (mp[p] <= gcd(a, b) && mp[p]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


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

const int nn = 2e5 + 8;
const ll MAX = 2e18;
int n, k;

pair<ll, int> a[nn];

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
    }
    int m = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || a[i].first != 1 || a[i].first != a[i - 1].first) {
            a[++m] = {a[i].first, 1};
        } else {
            a[m].second++;
        }
    }
    n = m;
    int res = 0;
    for (int i = 1; i <= n; i++) {
        ll sum = 0;
        ll prod = 1;
        int cnt = 0;
        for (int j = i; j <= n; j++) {
            if (a[j].first == 1) {
                if (prod % k == 0 && prod / k > sum && prod / k <= sum + a[j].second) {
                    res++;
                }
                sum += a[j].second;
            } else {
                cnt++;
                if (prod > MAX / a[j].first) break;
                sum += a[j].first;
                prod *= a[j].first;
                res += (sum * k == prod);
            }
        }
    }
    cout << res;
}


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

const int nn = 2e5 + 8;
const ll MAX = 2e18;
int n;
ll k;
int res;

pair<ll, ll> a[nn];

void calc(ll sum, ll prod, int l) {
    for (int i = l; i <= n; i++) {
        if (a[i].first == 1) {
            if (prod % k == 0 && prod / k > sum && prod / k <= sum + a[i].second) {
                res++;
            }
            sum += a[i].second;
        } else {
            if (prod > MAX / a[i].first) return;
            sum += a[i].first;
            prod *= a[i].first;
            res += (sum * k == prod);
        }
    }
}

int main() {
    scanf("%d %lld", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i].first);
    }
    int m = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || a[i].first != 1 || a[i].first != a[i - 1].first) {
            a[++m] = {a[i].first, 1};
        } else {
            a[m].second++;
        }
    }
    n = m;
    for (int i = 1; i <= n; i++) {
        int tmp = a[i].second;
        for (int j = 1; j <= tmp; j++) {
            a[i].second = j;
            calc(0, 1, i);
        }
    }
    printf("%d", res);
}


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

const int nn = 2e5 + 8;
const ll MAX = 1e18;
int n, k;

pair<ll, int> a[nn];

int main() {
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first;
    }
    int m = 0;
    for (int i = 1; i <= n; i++) {
        if (i == 1 || a[i].first != 1 || a[i].first != a[i - 1].first) {
            a[++m] = {a[i].first, 1};
        } else {
            a[m].second++;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        ll sum = 0;
        ll prod = 1;
        int cnt = 0;
        for (int j = i; j <= n; j++) {
            if (a[i].first == 1) {
                if (prod % k == 0 && prod / k > sum) {
                    res++;
                }
                sum += a[j].second;
            } else {
                cnt++;
                if (prod > MAX / a[j].first) break;
                sum += a[j].first;
                prod *= a[j].first;
                res += (sum * k == prod);
            }
        }
    }
    cout << res;
}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    ll cnt = 0;
    for(int j = 0; j<n ; j++){
        p = 1;
        s = cnt;
        for(int i = 0; i+j<n; i++){
            if(double(p) * double(a[i+j])>100000000000000000.0)
                break;
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones [i+j] >= s2){
                    ans+= 1;
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
        }
        if(ones[j]-cnt != 0){
            cnt++;
            j--;
        }else{
            cnt = 0;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    ll cnt = 0;
    if(k == 1){
        For(i,n)
                ans += ones[i];
    }
    for(int j = 0; j<n ; j++){
        p = 1;
        s = cnt;
        for(int i = 0; i+j<n; i++){
            if(double(p) * double(a[i+j])>100000000000000000.0)
                break;
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones [i+j] >= s2){
                    ans+= 1;
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
        }
        if(ones[j]-cnt != 0){
            cnt++;
            j--;
        }else{
            cnt = 0;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans++;
                    if(ones[j] && ones[j+i]){
                        if(true)
                            ans+= min(min(s2-s,ones[j]),ones[j+i]);
                    }
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    ll cnt = 0;
    if(k == 1){
        For(i,n)
                if(a[i]==1)
                ans += a[i]+ones[i];
    }else
    for(int j = 0; j<n ; j++){
        p = 1;
        s = cnt;
        for(int i = 0; i+j<n; i++){
            if(double(p) * double(a[i+j])>100000000000000000.0)
                break;
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones [i+j] >= s2){
                    ans+= 1;
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
        }
        if(ones[j]-cnt != 0){
            cnt++;
            j--;
        }else{
            cnt = 0;
        }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    ull a[n];
    For(i,n)
            cin>>a[i];
    ull p,s;
    ull ans = 0;
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n || i<61; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p == k*s)
                ans++;
            if(p> 10000000000)
                break;
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans++;
                    if(ones[j] && ones[j+i] && s + ones [i+j] >= s2){
                        if(+(ones[j],ones[i+j])-(s2-s)>0)
                            ans+= min(min(s2-s,ones[j]),ones[j+i]);
                    }
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,ll> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans+= min(min(s2-s,ones[j]),ones[j+i])+1;
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,int> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans++;
                    if(ones[j] && s<=s2 && s + ones [i+j] >= s2){
                        ans++;
                    }
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    ull a[n];
    For(i,n)
            cin>>a[i];
    ull p,s;
    ull ans = 0;
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n && i<61; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p == k*s)
                ans++;
            if(p> 10000000000)
                break;
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,int> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans++;
                    if(ones[j] && ones[j+i] && s + ones [i+j] >= s2){
                        ans++;
                    }
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    ull a[n];
    For(i,n)
            cin>>a[i];
    ull p,s;
    ull ans = 0;
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n && i<1000; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p == k*s)
                ans++;
            if(p> 10000000000)
                break;
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,int> ones;
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){

            }else
                a.push_back(1);
            ones[a.size()-1]++;
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(a[j+i]==1){
                if(p%k == 0){
                    ll s2 = p/k;
                    if(s<=s2 && s + ones[i+j] > s2){
                        ans++;
                    }
                }
                s += ones[i+j]-1;
            }else if(p == k*s)
                ans++;
            if(p> 10000000000)
                break;
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    vl a;
    map<ll,int> ones;
    if(0){
        For(i,n){
        ll num;
        cin>>num;
        a.push_back(num);}
    }else
    For(i,n){
        ll num;
        cin>>num;
        if(num == 1){
            if(a.size() != 0 && a.back() == 1){
                ones[a.size()-1]++;
            }else
                a.push_back(1);
        }else
            a.push_back(num);
    }
    ull p,s;
    ull ans = 0;
    n = a.size();
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p%k == 0){
                ll s2 = p/k;
                if(s<=s2 && s + ones[j] + ones [i+j] >= s2){
                    ans++;
                    if(ones[j] && ones[j+i] && s + ones [i+j] >= s2){
                        if(ones[j]+ones[i+j]-(s2-s)>0)
                            ans+= ones[j]+ones[i+j]-(s2-s);
                    }
                }
            }
            if(i != 0){
                s += ones[i+j];
            }
            if(p> 10000000000)
                break;
            if(j == -1){
                debug(p)
                        debug(s)
                        debug(ones[i+j])
                        debug("")
            }
        }
    }
    cout<<ans;

}


#include <bits/stdc++.h>
#define For(i,n) for(int i =0;i<n;i++)
#define vl vector<long long>
#define pll pair<long long,long long>
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long long ull;
using namespace std;
const ll oo = 1e18+23543;
const ll MAX = 1e5+1;
const ll MOD = 1e9 +7;

int main()
{
    fastIO;
#ifdef FFFeelipe
    freopen("/home/fffeelipe/Contests/in.txt" ,"r",stdin);
    freopen("/home/fffeelipe/Contests/out.txt","w",stdout);
#endif

    ull n, k;
    cin>>n>>k;
    ull a[n];
    For(i,n)
            cin>>a[i];
    ull p,s;
    ull ans = 0;
    for(int j = 0; j<n ; j++){
        p = 1;
        s = 0;
        for(int i = 0; i+j<n; i++){
            p *= a[i+j];
            s += a[j+i];
            if(p == k*s)
                ans++;
            if(p> 10000000000)
                break;
        }
    }
    cout<<ans;

}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef unsigned long long ll;
const int maxn = 200010;
const ll inf = 1e18;
int n, k;
int a[maxn], l[maxn];
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i - 1] != 1) l[i] = i - 1;
		else l[i] = l[i - 1];
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= n; i++){
		ll mul = a[i], sum = a[i];
		for(int j = i, last = l[i]; ; j = last, last = l[last]){
			ll tmp = mul - sum * k;
			if(tmp > 0 && tmp % k == 0 && tmp / k <= j - last - 1) ans++;
			if(last == 0) break;
			if(inf / a[last] < mul) break;
			mul *= a[last], sum += a[last] + j - last - 1;
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt;
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= cnt; i++){
		ll mul = 1, sum = 0;
		for(int j = no1[i - 1] + 1; j <= n; j++){
			if(1e18 / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt;
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= cnt; i++){
		ll mul = a[no1[i]], sum = a[no1[i]];
		for(int j = no1[i] + 1; j <= n; j++){
			mul *= a[j], sum += a[j];
			if(mul < 0) break;
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt;
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= cnt; i++){
		ll mul = a[no1[i]], sum = a[no1[i]];
		for(int j = no1[i - 1] + 1; j <= n; j++){
			if(1e18 / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt;
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= cnt; i++){
		ll mul = a[no1[i]], sum = a[no1[i]];
		for(int j = no1[i] + 1; j <= n; j++){
			if(1e18 / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt, r[maxn];
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	for(int i = 1; i <= cnt; i++){
		for(int j = no1[i - 1]; j < no1[i]; j++){
			r[j] = no1[i];
		}
	}
	for(int i = no1[cnt]; i <= n; i++){
		r[i] = n + 1;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= n; i++){
		ll mul = a[i], sum = a[i];
		for(int j = r[i]; ; j = r[j]){
			ll tmp = sum;
			sum += j - i - 1;
			if(tmp * k < mul && sum * k >= mul) ans++;
			if(j == n + 1) break;
			if(1e18 / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef unsigned long long ll;
const int maxn = 200010;
const ll inf = 1e18;
int n, k;
int a[maxn], no1[65], cnt, r[maxn];
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	for(int i = 1; i <= cnt; i++){
		for(int j = no1[i - 1]; j < no1[i]; j++){
			r[j] = no1[i];
		}
	}
	for(int i = no1[cnt]; i <= n; i++){
		r[i] = n + 1;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= n; i++){
		ll mul = a[i], sum = a[i];
		for(int j = r[i]; ; j = r[j]){
			ll tmp = mul - sum * k;
			sum += j - i - 1;
			if(tmp > 0 && tmp % k == 0 && tmp / k < j - i - 1) ans++;
			if(j == n + 1) break;
			if(inf / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;
typedef unsigned long long ll;
const int maxn = 200010;
int n, k;
int a[maxn], no1[65], cnt, r[maxn];
int main(){
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		if(a[i] != 1) no1[++cnt] = i;
	}
	for(int i = 1; i <= cnt; i++){
		for(int j = no1[i - 1]; j < no1[i]; j++){
			r[j] = no1[i];
		}
	}
	for(int i = no1[cnt]; i <= n; i++){
		r[i] = n + 1;
	}
	int ans = 0;
	if(k == 1) ans += n;
	for(int i = 1; i <= n; i++){
		ll mul = a[i], sum = a[i];
		for(int j = r[i]; ; j = r[j]){
			ll tmp = sum;
			sum += j - i - 1;
			if(tmp * k < mul && sum * k >= mul) ans++;
			if(j == n + 1) break;
			//if(1e18 / a[j] < mul) break;
			mul *= a[j], sum += a[j];
			if(mul < 0) break;
			if(mul == sum * k) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}


//author Eterna
#define xiongziliang nb
#define songwenqi AK
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<complex>
#include<numeric>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define Pi acos(-1.0)
#define eps 1e-15
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define pb(x) push_back(x)
#define lowbit(x) (x & -x)
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\in.txt", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\out.txt", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
inline int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
inline ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
ll arr[maxn + 5], cnt[maxn + 5], k, sum, up, x, product;
int n, m, res;
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> x;
		sum += x;
		if (x == 1) {
			if (arr[m] == 1)++cnt[m];
			else {
				arr[++m] = 1;
				cnt[m] = 1;
			}
		}
		else arr[++m] = x;
	}
	up = sum * k;
	for (int i = 1; i <= m; ++i) {
		sum = 0, product = 1;
		for (int j = i; j <= m; ++j) {
			if (arr[j] == 1) {
				if (product % k)sum += cnt[j];
				else {
					ll s = product / k;
					if (s - sum > 0 && (s - sum) <= cnt[j])++res;
					sum += cnt[j];
				}
			}
			else {
				product *= arr[j];
				sum += arr[j];
				if (k * sum == product)++res;
			}
			if (product > up)break;
		}
	}
	cout << res << endl;
	return 0;
}