Skip to content

Commit 51aab16

Browse files
authored
Merge pull request #831 from AlgorithmWithGod/0224LJH
[20250906] BOJ / G4 / 2로 몇번 나누어질까 / 이종환
2 parents e8a7060 + 08c1b1d commit 51aab16

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```java
2+
import java.io.IOException;
3+
import java.io.*;
4+
import java.util.*;
5+
6+
7+
public class Main {
8+
static long from,to,sum;
9+
static long[] cnts = new long[61];
10+
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
process();
15+
print();
16+
}
17+
18+
public static void init() throws IOException {
19+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
20+
StringTokenizer st = new StringTokenizer(br.readLine());
21+
from = Long.parseLong(st.nextToken());
22+
to = Long.parseLong(st.nextToken());
23+
24+
25+
}
26+
27+
public static void process() throws IOException {
28+
for (int i = 0; i < 61; i++) {
29+
long num = 1L << i;
30+
31+
long cnt = to/num - from/num;
32+
if (from%num == 0) cnt++;
33+
34+
cnts[i] = cnt;
35+
}
36+
37+
sum = 0;
38+
long pre = 0;
39+
for (int i = 60; i >= 0; i--) {
40+
long num = 1L << i;
41+
42+
sum += (cnts[i]-pre) * num;
43+
pre = cnts[i];
44+
}
45+
46+
}
47+
48+
49+
50+
51+
52+
53+
54+
public static void print() {
55+
System.out.println(sum);
56+
}
57+
}
58+
59+
```

0 commit comments

Comments
 (0)