Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 410a1bb

Browse files
committed
clean code
1 parent 4b81f52 commit 410a1bb

File tree

32 files changed

+176
-129
lines changed

32 files changed

+176
-129
lines changed

‎algo-core/src/main/java/template/seg/SparseTable_gcd.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ long query(int l, int r) {
2929
// bits.Len:
3030
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
3131
int bitsLen(long x) {
32-
if (x == 0) return 0;
32+
// if (x == 0) return 0;
3333
// return Long.toBinaryString(x).length();
34-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
34+
// return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
35+
return 64 - Long.numberOfLeadingZeros(x);
3536
}
3637

3738
static long getGCD(long num1, long num2) {

‎atcoder/atcoder-grand/src/main/java/c015/Agc015_d.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ private static String solve() {
3636
// bits.Len:
3737
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
3838
static int bitsLen(long x) {
39-
if (x == 0) return 0;
40-
// return Long.toBinaryString(x).length();
41-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
39+
return 64 - Long.numberOfLeadingZeros(x);
4240
}
4341
}
4442
/*

‎atcoder/atcoder-regular/src/main/java/dwacon5th_prelims/Dwacon5thPrelims_b.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ private static String solve() {
4747
// bits.Len:
4848
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
4949
static int bitsLen(long x) {
50-
if (x == 0) return 0;
51-
return Long.toBinaryString(x).length();
52-
// return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
50+
return 64 - Long.numberOfLeadingZeros(x);
5351
}
5452
}
5553
/*

‎codeforces/codeforces-03/src/main/java/p276/CF276D.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ private static String solve() {
2020
// bits.Len:
2121
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
2222
static int bitsLen(long x) {
23-
if (x == 0) return 0;
24-
// return Long.toBinaryString(x).length();
25-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
23+
return 64 - Long.numberOfLeadingZeros(x);
2624
}
2725

2826
}

‎codeforces/codeforces-05/src/main/java/p474/CF474F.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ long query(int l, int r) {
153153
// bits.Len:
154154
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
155155
int bitsLen(long x) {
156-
if (x == 0) return 0;
157-
// return Long.toBinaryString(x).length();
158-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
156+
return 64 - Long.numberOfLeadingZeros(x);
159157
}
160158
}
161159

‎codeforces/codeforces-07/src/main/java/p689/CF689D.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ static int query(int l, int r) {
5454
// bits.Len:
5555
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
5656
static int bitsLen(long x) {
57-
if (x == 0) return 0;
58-
return Long.toBinaryString(x).length();
57+
return 64 - Long.numberOfLeadingZeros(x);
5958
}
6059
}
6160
/*

‎codeforces/codeforces-10/src/main/java/p960/CF960C.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ private static String solve() {
3535
// bits.Len:
3636
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
3737
static int bitsLen(long x) {
38-
if (x == 0) return 0;
39-
return Long.toBinaryString(x).length();
38+
return 64 - Long.numberOfLeadingZeros(x);
4039
}
4140
}
4241
/*

‎codeforces/codeforces-15/src/main/java/p1420/CF1420B.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ private static String solve() {
3333
// bits.Len:
3434
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
3535
static int bitsLen(long x) {
36-
if (x == 0) return 0;
37-
// return Long.toBinaryString(x).length();
38-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
36+
return 64 - Long.numberOfLeadingZeros(x);
3937
}
4038
}
4139
/*

‎codeforces/codeforces-19/src/main/java/p1863/CF1863F.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ private static String solve() {
5151
// bits.Len:
5252
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
5353
static int bitsLen(long x) {
54-
if (x == 0) return 0;
5554
// Time limit exceeded on test 5
55+
// if (x == 0) return 0;
5656
// return Long.toBinaryString(x).length();
57-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
57+
return 64 - Long.numberOfLeadingZeros(x);
5858
}
5959
}
6060
/*

‎codeforces/codeforces-19/src/main/java/p1883/CF1883E.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ private static String solve() {
3737
// bits.Len:
3838
// Len returns the minimum number of bits required to represent x; the result is 0 for x == 0.
3939
static int bitsLen(long x) {
40-
if (x == 0) return 0;
41-
// return Long.toBinaryString(x).length();
42-
return Long.numberOfTrailingZeros(Long.highestOneBit(x)) + 1;
40+
return 64 - Long.numberOfLeadingZeros(x);
4341
}
4442
}
4543
/*

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /