fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. long x = sc.nextLong();
  7.  
  8. for (long y = 1; y <= (long) 1e6; y++) { // 为了效率,只枚举到1e6,一般足够找出最小的y
  9. long z = x ^ y;
  10. if (z == 0) continue;
  11. if (x % z == 0 && y % z == 0) {
  12. System.out.println(y);
  13. return;
  14. }
  15. }
  16.  
  17. System.out.println(-1);
  18. }
  19. }
  20.  
Success #stdin #stdout 0.14s 56640KB
stdin
6
stdout
4