-
Notifications
You must be signed in to change notification settings - Fork 27
/
10719.go
46 lines (40 loc) · 817 Bytes
/
10719.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// UVa 10719 - Quotient Polynomial
package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"
)
func solve(out io.Writer, k int, a1 []int) {
a2 := make([]int, len(a1)-1)
a2[0] = a1[0]
fmt.Fprintf(out, "q(x): %d", a2[0])
for i := 1; i < len(a2); i++ {
a2[i] = k*a2[i-1] + a1[i]
fmt.Fprintf(out, " %d", a2[i])
}
fmt.Fprintf(out, "\nr = %d\n\n", a2[len(a2)-1]*k+a1[len(a1)-1])
}
func main() {
in, _ := os.Open("10719.in")
defer in.Close()
out, _ := os.Create("10719.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var k, tmp int
for s.Scan() {
fmt.Sscanf(s.Text(), "%d", &k)
s.Scan()
var a []int
for r := strings.NewReader(s.Text()); ; {
if _, err := fmt.Fscanf(r, "%d", &tmp); err != nil {
break
}
a = append(a, tmp)
}
solve(out, k, a)
}
}