//#define _GLIBCXX_DEBUG #include using namespace std; using ll = long long; #define pp pair #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define ld long double #define al(a) (a).begin(),(a).end() #define mk make_pair #define check cout<<"?"<>t; vector pr(5000001,1); for(ll i=1;i<=5000000;i++)for(ll j=i;j<=5000000;j+=i) pr[j]=0; rep(_,t){ ll a,p; cin>>a>>p; if(pr[p]==0){ printf("-1\n"); continue; } a%=p; if(a==0){ printf("0\n"); continue; } printf("1\n"); } }