File tree Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Expand file tree Collapse file tree 2 files changed +76
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ . "fmt"
5
+ "io"
6
+ )
7
+
8
+ // github.com/EndlessCheng/codeforces-go
9
+ func CF1204E (in io.Reader , out io.Writer ) {
10
+ const mod = 998244853
11
+ pow := func (x , n int64 ) (res int64 ) {
12
+ res = 1
13
+ for ; n > 0 ; n >>= 1 {
14
+ if n & 1 > 0 {
15
+ res = res * x % mod
16
+ }
17
+ x = x * x % mod
18
+ }
19
+ return res
20
+ }
21
+
22
+ var n , m int
23
+ Fscan (in , & n , & m )
24
+ F := make ([]int64 , n + m + 1 )
25
+ F [0 ] = 1
26
+ for i := 1 ; i <= n + m ; i ++ {
27
+ F [i ] = F [i - 1 ] * int64 (i ) % mod
28
+ }
29
+ invF := make ([]int64 , n + m + 1 )
30
+ invF [n + m ] = pow (F [n + m ], mod - 2 )
31
+ for i := n + m ; i > 0 ; i -- {
32
+ invF [i - 1 ] = invF [i ] * int64 (i ) % mod
33
+ }
34
+ C := func (n , k int ) int64 { return F [n ] * invF [k ] % mod * invF [n - k ] % mod }
35
+ ans := int64 (0 )
36
+ for i := 1 ; i <= n ; i ++ {
37
+ if i > n - m {
38
+ ans += C (n + m , n - i )
39
+ } else {
40
+ ans += C (n + m , n )
41
+ }
42
+ }
43
+ Fprint (out , ans % mod )
44
+ }
45
+
46
+ //func main() { CF1204E(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/1204/E
9
+ // https://codeforces.com/problemset/status/1204/problem/E
10
+ func TestCF1204E (t * testing.T ) {
11
+ // just copy from website
12
+ rawText := `
13
+ inputCopy
14
+ 0 2
15
+ outputCopy
16
+ 0
17
+ inputCopy
18
+ 2 0
19
+ outputCopy
20
+ 2
21
+ inputCopy
22
+ 2 2
23
+ outputCopy
24
+ 5
25
+ inputCopy
26
+ 2000 2000
27
+ outputCopy
28
+ 674532367`
29
+ testutil .AssertEqualCase (t , rawText , 0 , CF1204E )
30
+ }
You can’t perform that action at this time.
0 commit comments