File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ . "fmt"
5
+ "io"
6
+ "math/bits"
7
+ )
8
+
9
+ // github.com/EndlessCheng/codeforces-go
10
+ func CF768B (in io.Reader , out io.Writer ) {
11
+ var n , l , r uint64
12
+ Fscan (in , & n , & l , & r )
13
+ tot := (uint64 (1 )<< bits .Len64 (n ) - 1 ) >> 1
14
+ f := func (m uint64 ) (res uint64 ) {
15
+ for n , tot := n , tot ; m > 0 ; n >>= 1 {
16
+ if m >= tot {
17
+ m -= tot
18
+ res += n / 2
19
+ if m > 0 {
20
+ m --
21
+ res += n & 1
22
+ }
23
+ }
24
+ tot >>= 1
25
+ }
26
+ return
27
+ }
28
+ Fprint (out , f (r )- f (l - 1 ))
29
+ }
30
+
31
+ //func main() { CF768B(os.Stdin, os.Stdout) }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "github.com/EndlessCheng/codeforces-go/main/testutil"
5
+ "testing"
6
+ )
7
+
8
+ // https://codeforces.com/problemset/problem/768/B
9
+ // https://codeforces.com/problemset/status/768/problem/B
10
+ func TestCF768B (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 7 2 5
15
+ outputCopy
16
+ 4
17
+ inputCopy
18
+ 10 3 10
19
+ outputCopy
20
+ 5`
21
+ testutil .AssertEqualCase (t , rawText , 0 , CF768B )
22
+ }
You can’t perform that action at this time.
0 commit comments