File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments