From dd5bbb300cb1123bfa1338b9b7588998ec4949ee Mon Sep 17 00:00:00 2001 From: VacancyIF <45335949+VacancyIF@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:47:14 +0800 Subject: [PATCH] Update Challenge.java --- src/main/java/com/bytelegend/Challenge.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/bytelegend/Challenge.java b/src/main/java/com/bytelegend/Challenge.java index 20239d5..7eb218c 100644 --- a/src/main/java/com/bytelegend/Challenge.java +++ b/src/main/java/com/bytelegend/Challenge.java @@ -17,7 +17,7 @@ public static void main(String[] args) { * (`+`). */ public static int multiplyBy31(int n) { - return 0; + return (n << 5) - n; } /** @@ -32,6 +32,10 @@ public static int multiplyBy31(int n) { * addition sign (`+`). */ public static int divideBy2ThenMinus1(int n) { - return 0; + if (n < 0) { + int m = -n; + return -(m >> 1) - 1; + } + return (n >> 1) - 1; } }