Problem Statement
Given two integers: L and R,
find the maximal values of A xor B given, L ≤ A ≤ B ≤ R
Input Format
The input contains two lines, L is present in the first line.
R in the second line.
The input contains two lines, L is present in the first line.
R in the second line.
Constraints
1 ≤ L ≤ R ≤ 103
1 ≤ L ≤ R ≤ 103
Output Format
The maximal value as mentioned in the problem statement.
The maximal value as mentioned in the problem statement.
Code
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 | import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; /** * @author Rakesh KR */ public class Solution { static int maxXor(int l, int r) { int big = 0; if(l>=1 && r<=10*10*10){ for(int i = l ; i <= r ;i++){ for(int j = l; j <= r ; j++){ int val = i^j; big = (big>val) ? big : val ; } } } return big; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int res; int _l; _l = Integer.parseInt(in.nextLine()); int _r; _r = Integer.parseInt(in.nextLine()); res = maxXor(_l, _r); System.out.println(res); } } |
Comments
Post a Comment