#yukicoder 187 中華風(Hard) 多倍長解法 #exec gcd #Reference: https://x.com/_miz_tom/status/1842086118990479854 exec('def gcd(x, y):\n' + ' x, y = abs(x), abs(y)\n' + ' if x == 0: return y\n' + ' if not (y := y % x): return x\n if not (x := x % y): return y\n' * 300 + ' return gcd(x, y)') def CRT(n1, M1, n2, M2): #smallest n ≡ n1 mod M1 ≡ n2 mod M2 if (n1 - n2) % ( G := gcd(M1, M2) ) != 0: return -1 return (n1 - n2) * pow(M2 // G, -1, M1 // G) % M1 * M2 // G + n2 #入力受取 N = int(input()) P = [tuple(map(int, input().split())) for _ in range(N)] MOD = 10 ** 9 + 7 #CRTを実行 rem, mod = 0, 1 for Xi, Yi in P: rem = CRT(rem, mod, Xi, Yi) if rem == -1: break mod = mod * Yi // gcd(mod, Yi) if rem == -1: #解なし print(-1) elif rem == 0: #正整数を探す → lcm(Yi) print(mod % MOD) else: #remを出力 print(rem % MOD)