The approach to solve this problem heavily relies on the property that A+B = (A^B) + 2*(A&B) The interactor gives us the value of A1^k + A2^k + A3^k ... AN^k Using the above mentioned property, we know A + k = (A^k) + 2*(A&K) Hence, (A^k) = A+k - (2*(A&K)) Which implies -> A1^k + A2^k + A3^k ... AN^k = A1 + A2 + A3 .. AN + N*k - 2*(A1&k + A2&k + A3&k .. AN&k) Lets us denote the A1 + A2 + A3 .. AN
| 24 | as Ai <= 10^6, we do not need any further questions. |
| 25 | */ |
| 26 | int32_t main() |
| 27 | { |
| 28 | int t; |
| 29 | cin>>t; |
| 30 | while(t--){ |
| 31 | int n; |
| 32 | cin>>n; |
| 33 | int s=0,o,i=1; |
| 34 | int d[21]={0}; |
| 35 | cout<<1<<" "<<(1<<20)<<endl; |
| 36 | cin>>s; |
| 37 | s = s - n*(1<<20); //Sum for Equation 1 |
| 38 | if(s&1){ |
| 39 | d[0] = 1; //The 0th bit could simply be obtained by taking an AND with 1 |
| 40 | } |
| 41 | else{ |
| 42 | d[0] = 0; |
| 43 | } |
| 44 | while(i!=20){//Remaining 19 bits could be obtained by the remaining 19 questions. |
| 45 | cout<<1<<" "<<(1<<i)<<endl; |
| 46 | cin>>o; |
| 47 | d[i] = (s + n*(1<<i) - o)/(1<<(i+1));//((1<<i)*2) = (1<<(i+1)) |
| 48 | i++; |
| 49 | } |
| 50 | int x=0; |
| 51 | int y=1; |
| 52 | for(int i=0;i<=19;++i){ |
| 53 | x += (d[i]%2)*y; |
| 54 | y = y*2; |
| 55 | } |
| 56 | cout<<2<<" "<<x<<endl; |
| 57 | int ans; |
| 58 | cin>>ans; |
| 59 | if(ans==-1){ |
| 60 | return 0; |
| 61 | } |
| 62 | } |
| 63 | return 0; |
| 64 | } |
nothing calls this directly
no outgoing calls
no test coverage detected