#include #include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 //互いに素なmとその余りrに合致する値をmintで返す mint Garner(vector m,vector r){ int n = m.size(); /* rep(i,n){ cout< t(n); rep(i,n){ long long cur = 0LL; long long cm = 1LL; rep(j,i){ cur += t[j] * cm; cur %= m[i]; cm *= m[j]; cm %= m[i]; } cur = r[i] - cur; cur %= m[i]; if(cur<0)cur += m[i]; cur *= inv_mod(cm,m[i]); cur %= m[i]; t[i] = cur; } mint ret = 0; mint cm = 1; rep(i,n){ ret += cm * t[i]; cm *= m[i]; } return ret; } int main(){ int N; cin>>N; vector r(N),m(N); rep(i,N)cin>>r[i]>>m[i]; map mp; rep(i,N){ long long tm = m[i]; map temp; for(long long j=2;j*j<=tm;j++){ while(tm%j==0){ tm /= j; if(temp.count(j)){ temp[j] *= j; } else{ temp[j] = j; } } } if(tm!=1)temp[tm] = tm; for(auto a:temp){ mp[a.first] = max(mp[a.first],a.second); } } for(auto a:mp){ // cout< rr,mm; rep(i,N){ long long temp = gcd(m[i],a.second); if(temp==1)continue; rr.push_back(r[i]%temp); mm.push_back(temp); m[i] /= temp; r[i] %= m[i]; } auto ret = crt(rr,mm); if(ret.second==0){ cout<<-1<(r.size(),0LL)){ mint ans = 1; for(auto a:mp){ ans *= a.second; } cout<