F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

TDL

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1590    Accepted Submission(s): 758


Problem Description
For a positive integer $n$, let's denote function $f(n,m)$ as the $m$-th smallest integer $x$ that $x>n$ and $\gcd(x,n)=1$. For example, $f(5,1)=6$ and $f(5,5)=11$.

You are given the value of $m$ and $(f(n,m)-n)\oplus n$, where ``$\oplus$'' denotes the bitwise XOR operation. Please write a program to find the smallest positive integer $n$ that $(f(n,m)-n)\oplus n=k$, or determine it is impossible.
 

Input
The first line of the input contains an integer $T(1\leq T\leq 10)$, denoting the number of test cases.

In each test case, there are two integers $k,m(1\leq k\leq 10^{18},1\leq m\leq 100)$.
 

Output
For each test case, print a single line containing an integer, denoting the smallest $n$. If there is no solution, output ``$\texttt{-1}$'' instead.
 

Sample Input
2 3 5 6 100
 

Sample Output
5 -1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 03:27:53, Gzip enabled