Logo
(追記) (追記ここまで)

18593번 - TDL 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB94413037.975%

문제

For a positive integer n, let us denote function f(n, m) as the m-th smallest integer x such that x > n and gcd(x, n) = 1. For example, f(5, 1) = 6 and f(5, 5) = 11.

You are given the values of m and (f(n, m) − n) ⊕ n, where “⊕” denotes the bitwise XOR operation. Please write a program to find the smallest positive integer n such that (f(n, m) − n) ⊕ n = k, or determine it is impossible.

입력

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

Each test case is denoted by a single line containing two integers k and m (1 ≤ k ≤ 1018, 1 ≤ m ≤ 100).

출력

For each test case, print a single line containing a single integer: the smallest value of n. If there is no solution, output “-1” instead.

제한

예제 입력 1

2
3 5
6 100

예제 출력 1

5
-1

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 1: Songyang Chen Contest 2 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /