#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 mod M ≡ n1 mod M1 ≡ n2 mod M2 if (n1 - n2) % ( G := gcd(M1, M2) ) != 0: return (0, 0) return ( (n1 - n2) * pow( c := M2 // G, -1, M1 // G) % M1 * M2 // G + n2, M1 * c ) #入力受取 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, mod = CRT(rem, mod, Xi, Yi) if mod == 0: break if mod == 0: #解なし print(-1) elif rem == 0: #正整数を探す → lcm(Yi) print(mod % MOD) else: #remを出力 print(rem % MOD)