-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path884.go
More file actions
44 lines (38 loc) · 665 Bytes
/
884.go
File metadata and controls
44 lines (38 loc) · 665 Bytes
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
// UVa 884 - Factorial Factors
package main
import (
"fmt"
"os"
)
const max = 1000001
var factors = func() []int {
factors := make([]int, max)
for i := range factors {
factors[i] = 1
}
factors[1] = 0
for i := 2; i < max; i++ {
if factors[i] == 1 {
for j := 2; i*j < max; j++ {
factors[i*j] = factors[i] + factors[j]
}
}
}
for i := 2; i < max; i++ {
factors[i] += factors[i-1]
}
return factors
}()
func main() {
in, _ := os.Open("884.in")
defer in.Close()
out, _ := os.Create("884.out")
defer out.Close()
var n int
for {
if _, err := fmt.Fscanf(in, "%d", &n); err != nil {
break
}
fmt.Fprintln(out, factors[n])
}
}