using System; using System.Collections.Generic; using System.Linq; // https://yukicoder.me/problems/no/3624 // yukicoder 3624 Product class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("4"); WillReturn.Add("1 4"); WillReturn.Add("8 15"); WillReturn.Add("45 123"); WillReturn.Add("0 1000000000"); //12 //-1 //4032 //288230375614840832 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static long[] GetSplitArr(string pStr) { return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray(); } static void Main() { List InputList = GetInputList(); long[] wkArr = { }; Action SplitAct = (pStr) => wkArr = GetSplitArr(pStr); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); long L = wkArr[0]; long R = wkArr[1]; long Answer = Solve(L, R); Console.WriteLine(Answer); } } static long Solve(long pL, long pR) { if (pL == 0 && pR == 0) return 0; string BinStrL = Convert.ToString(pL, 2); string BinStrR = Convert.ToString(pR, 2); int Length = Math.Max(BinStrL.Length, BinStrR.Length); BinStrL = BinStrL.PadLeft(Length, '0'); BinStrR = BinStrL.PadLeft(Length, '0'); if (BinStrL[0] == '1' && BinStrR[0] == '1') return -1; string NewBinStrL = "0"; string NewBinStrR = "1"; for (long I = 1; I <= Length - 1; I++) { NewBinStrL += 1; NewBinStrR += 0; } long LongValL = Convert.ToInt64(NewBinStrL, 2); long LongValR = Convert.ToInt64(NewBinStrR, 2); return LongValL * LongValR; } }