-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11827.go
52 lines (45 loc) · 812 Bytes
/
11827.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
47
48
49
50
51
52
// UVa 11827 - Maximum GCD
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func gcd(a, b int) int {
if b == 0 {
return a
}
return gcd(b, a%b)
}
func solve(num []int) int {
var max int
for i, l := 0, len(num); i < l-1; i++ {
for j := i + 1; j < l; j++ {
if g := gcd(num[i], num[j]); g > max {
max = g
}
}
}
return max
}
func main() {
in, _ := os.Open("11827.in")
defer in.Close()
out, _ := os.Create("11827.out")
defer out.Close()
s := bufio.NewScanner(in)
s.Split(bufio.ScanLines)
var n, tmp int
s.Scan()
for fmt.Sscanf(s.Text(), "%d", &n); n > 0 && s.Scan(); n-- {
var num []int
for r := strings.NewReader(s.Text()); ; {
if _, err := fmt.Fscanf(r, "%d", &tmp); err != nil {
break
}
num = append(num, tmp)
}
fmt.Fprintln(out, solve(num))
}
}