1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Przykładowe poprawne rozwiązanie do zadania Dzielniki.
#include "dzilib.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll los(ll a, ll b) {
  return rng()%(b-a+1)+a;
}
ll gend() { // zwraca losowa liczbe z prezdzialu [0, 10^18)
  return los(0, 999999999)*1000000000+los(0, 999999999);
}
ll losd(ll a, ll b) {
  return gend()%(b-a+1)+a;
}
ll n;
map<ll,ll>mp;
ll pytaj(ll x) {
  if(mp.find(x)==mp.end()) mp[x]=Ask(x);
  return mp[x];
}
ll licz(ll x, ll k) {
  if((1ll<<k)>n) return (1ll<<k)-x;
  ll a=pytaj(x), b=pytaj(x+(1ll<<k));
  bool ok=false;
  for(ll i=k+2; i<=60; ++i) if(a%i==0) ok=true;
  if(b%(k+1)!=0) ok=false;
  if(ok) {
    ll p=licz(x, k+1);
    if(p!=-1) return p;
  }
  ok=false;
  for(ll i=k+2; i<=60; ++i) if(b%i==0) ok=true;
  if(a%(k+1)!=0) ok=false;
  if(ok) {
    ll p=licz(x+(1ll<<k), k+1);
    if(p!=-1) return p;
  }
  return -1;
}
void solve() {
  mp.clear();
  ll pocz=losd(0, 40000000000000);
  if(n==1000000000) pocz=losd(0, 2137);
  Answer(licz(pocz, 0));
}
int main() {
  n=max(GetN(), 1000000000ll);
  ll _=GetT();
  while(_--) solve();
}