baekjoon 20260208

This commit is contained in:
songyc macbook 2026-02-08 21:36:22 +09:00
parent 2b24a0a06c
commit 9eb6786614
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,17 @@
dp = [0] * 55
for n in range(1,55) :
dp[n] = 2*dp[n-1] + (1 << (n-1))
def countOne(N) :
ans = 0
for n in range(54,0,-1) :
MSB = N & (1 << (n-1))
if MSB :
N -= MSB
ans += dp[n-1] + (N + 1)
return ans
A, B = map(int, input().split())
print(countOne(B) - countOne(A-1))

View File

@ -0,0 +1,6 @@
export {};
const [A, B]: number[] = require("fs").readFileSync(0).toString().trim().split(" ").map(Number);
console.log(
Math.abs(Math.floor((A-1)/4) - Math.floor((B-1)/4)) +
Math.abs((A-1)%4 - (B-1)%4)
);