From e5d5bd3d999a703a44ccf00b4662a478c408c013 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 11 Jul 2025 17:45:44 +0900 Subject: [PATCH] =?UTF-8?q?[20250711]=20BOJ=20/=20G2=20/=201=EC=9D=98=20?= =?UTF-8?q?=EA=B0=9C=EC=88=98=20=EC=84=B8=EA=B8=B0=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\210\230 \354\204\270\352\270\260.md" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 "LiiNi-coder/202507/11 BOJ 1\354\235\230 \352\260\234\354\210\230 \354\204\270\352\270\260.md" diff --git "a/LiiNi-coder/202507/11 BOJ 1\354\235\230 \352\260\234\354\210\230 \354\204\270\352\270\260.md" "b/LiiNi-coder/202507/11 BOJ 1\354\235\230 \352\260\234\354\210\230 \354\204\270\352\270\260.md" new file mode 100644 index 00000000..7a59a387 --- /dev/null +++ "b/LiiNi-coder/202507/11 BOJ 1\354\235\230 \352\260\234\354\210\230 \354\204\270\352\270\260.md" @@ -0,0 +1,67 @@ +# 코드 +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.math.BigInteger; + +public class Main { + private static BufferedReader br; + + public static void main(String[] args) throws IOException { + br = new BufferedReader(new InputStreamReader(System.in)); + String[] temp1 = br.readLine().split(" "); + BigInteger l = new BigInteger(temp1[0]); + BigInteger r = new BigInteger(temp1[1]); + + BigInteger result = BigInteger.ZERO; + + for (int exponent = 0; exponent <= 63; exponent++) { + BigInteger blockSize = BigInteger.ONE.shiftLeft(exponent); + if (blockSize.compareTo(r) > 0) break; + + BigInteger lBlockIdx = l.divide(blockSize); + BigInteger rBlockIdx = r.divide(blockSize); + + if (lBlockIdx.equals(rBlockIdx)) { + if (getBitAtBlock(lBlockIdx)) { + result = result.add(r.subtract(l).add(BigInteger.ONE)); + } + } else { + if (getBitAtBlock(lBlockIdx)) { + BigInteger lEnd = blockSize.multiply(lBlockIdx.add(BigInteger.ONE)); + result = result.add(lEnd.subtract(l)); + } + if (getBitAtBlock(rBlockIdx)) { + BigInteger rStart = blockSize.multiply(rBlockIdx); + result = result.add(r.subtract(rStart).add(BigInteger.ONE)); + } + + // C + BigInteger offsetBlock = rBlockIdx.subtract(lBlockIdx).subtract(BigInteger.ONE); + BigInteger half = offsetBlock.divide(BigInteger.TWO); + if (offsetBlock.mod(BigInteger.TWO).equals(BigInteger.ZERO)) { + result = result.add(blockSize.multiply(half)); + } else { + if (getBitAtBlock(rBlockIdx)) { + result = result.add(blockSize.multiply(half)); + } else { + result = result.add(blockSize.multiply(half).add(blockSize)); + } + } + } + } + + System.out.println(result); + br.close(); + } + + private static boolean getBitAtBlock(BigInteger idx) { + return idx.mod(BigInteger.TWO).equals(BigInteger.ONE); + } +} + +``` + +#결과 +맞았습니다!! 14484kB 104ms