#include #include long long int power(long long int a, long long int b, int p) { long long int ans = 1; long long int k = a; while(b) { if(b%2==1) ans*=k, ans%=p; k*=k, k%=p; b/=2; } return ans; } long long int inv(long long int a, int p) { return power(a,p-2,p); } long long int fact[110]; std::vector ans; long long int check[100010]; std::vector save[1010][110]; int main() { fact[0] = 1; int T; scanf("%d",&T); while(T--) { ans.clear(); int a,b; scanf("%d%d",&a,&b); if(!save[a][b].empty()) { for(int i=0;i=b) goto u; i2 = (i2*i)%p; s = (s*t)%p; } } } u:; for(int i=1;i<=a*b;i++) if(check[i]==1) ans.push_back(i); save[a][b] = ans; for(int i=0;i