class Sieve: def __init__(self, n): self.plist = [2] min_prime_factor = [2, 0]*(n//2+1) for x in range(3, n+1, 2): if min_prime_factor[x] == 0: min_prime_factor[x] = x self.plist.append(x) if x**2 > n: continue for y in range(x**2, n+1, 2*x): if min_prime_factor[y] == 0: min_prime_factor[y] = x self.min_prime_factor = min_prime_factor def isprime(self, x): return self.min_prime_factor[x] == x def pf(self, x): pp, ee = [], [] while x > 1: mpf = self.min_prime_factor[x] if pp and mpf == pp[-1]: ee[-1] += 1 else: pp.append(mpf) ee.append(1) x //= mpf return pp, ee # unsorted def factor(self, a): ff = [1] pp, ee = self.pf(a) for p, e in zip(pp, ee): ff, gg = [], ff w = p for _ in range(e): for f in gg: ff.append(f*w) w *= p ff += gg return ff from functools import lru_cache @lru_cache(None) def ask(i, j): print("?", i+1, j+1, flush=True) res = int(input()) return res n = int(input()) if n==1: print("!",1,1,flush=True) exit() sv = Sieve(n) p = sv.plist[-1] aa = [0]*n bb = [0]*n for j in range(n):bb[j] = ask(0, j) a0=min(bb) aa[0]=a0 if a0==p: for j in range(n):bb[j]//=p js=[] for j in range(n): if bb[j]==1:js.append(j) l,r=js if ask(1,l)