From c40ee97e12a90e53737b018c67a1b4727162826c Mon Sep 17 00:00:00 2001 From: VacancyIF <45335949+VacancyIF@users.noreply.github.com> Date: Thu, 23 Nov 2023 17:03:17 +0800 Subject: [PATCH] Update Challenge.java --- src/main/java/com/bytelegend/Challenge.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/bytelegend/Challenge.java b/src/main/java/com/bytelegend/Challenge.java index 20239d5..3fccd13 100644 --- a/src/main/java/com/bytelegend/Challenge.java +++ b/src/main/java/com/bytelegend/Challenge.java @@ -2,12 +2,15 @@ public class Challenge { public static void main(String[] args) { - System.out.println(multiplyBy31(0)); - System.out.println(multiplyBy31(1)); - System.out.println(multiplyBy31(5)); - System.out.println(divideBy2ThenMinus1(1)); - System.out.println(divideBy2ThenMinus1(4)); - System.out.println(divideBy2ThenMinus1(7)); +// System.out.println(multiplyBy31(0)); +// System.out.println(multiplyBy31(2)); +// System.out.println(multiplyBy31(5)); + System.out.println(-97 / 2 - 1); + System.out.println(-99 / 2 - 1); + System.out.println(-98 / 2 - 1); + System.out.println(divideBy2ThenMinus1(-97)); + System.out.println(divideBy2ThenMinus1(-99)); + System.out.println(divideBy2ThenMinus1(-98)); } /** @@ -17,7 +20,7 @@ public static void main(String[] args) { * (`+`). */ public static int multiplyBy31(int n) { - return 0; + return (n << 5) - n; } /** @@ -32,6 +35,6 @@ public static int multiplyBy31(int n) { * addition sign (`+`). */ public static int divideBy2ThenMinus1(int n) { - return 0; + return ((n+1) >> 1 )- 1; } }