package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getInt() } return ret } func getString() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } func extGCD(a, b int) (int, int, int) { if b == 0 { return a, 1, 0 } d, y, x := extGCD(b, a%b) y -= a / b * x return d, x, y } func modInv(a, m int) int { d, x, _ := extGCD(a, m) if d != 1 { return -1 } x %= m if x < 0 { x += m } return x } func garner(r, m []int) int { n := len(r) mProd := 1 x := r[0] % m[0] for i := 1; i < n; i++ { mProd *= m[i-1] t := ((r[i] - x) * modInv(mProd, m[i])) % m[i] if t < 0 { t += m[i] } x += t * mProd } return x } // PfsMap : 素因数分解し、マップを作成 func PfsMap(n int) map[int]int { pfs := make(map[int]int) for n%2 == 0 { pfs[2] = pfs[2] + 1 n = n / 2 } for i := 3; i*i <= n; i = i + 2 { for n%i == 0 { pfs[i] = pfs[i] + 1 n = n / i } } if n > 2 { pfs[n] = pfs[n] + 1 } return pfs } func main() { sc.Split(bufio.ScanWords) N := getInt() x := make([]int, N) y := make([]int, N) m := make(map[int]int) pos := make(map[int]int) for i := 0; i < N; i++ { x[i], y[i] = getInt(), getInt() p := PfsMap(y[i]) // out(p) for j, n := range p { t := m[j] if t < n { m[j] = n pos[j] = i } } } // out(y) for p := range m { for i := 0; i < N; i++ { if pos[p] == i { continue } for y[i]%p == 0 { y[i] /= p } } } // out(m, pos) // out(y) out(garner(x, y)) }