aboutsummaryrefslogtreecommitdiff
path: root/2015/20/puzzles.go
blob: 5f2d37f8fd1b0ec3e2b49934468d4e2fd37946db (plain) (blame)
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
53
54
55
56
57
58
package main

import (
	"fmt"
	"math"
	"os"
)

func calc(n int) int {
	acc := 0
	s := math.Sqrt(float64(n))

	if s == math.Trunc(s) {
		acc += int(s)
	} else {
		s = math.Ceil(s)
	}

	for i := 1; i < int(s); i++ {
		if n % i == 0 {
			/* START PART 2 */
			ndi := n / i
			if ndi <= 50 {
				acc += i + ndi
			} else if i <= 50 {
				acc += ndi
			}
			/* END PART 2 START PART 1 */
			acc += i + n / i
			/* END PART 1 */
		}
	}

	return acc
}

func main() {
	file, err := os.Open("input")
	if err != nil {
		fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
		os.Exit(1)
	}

	var n int
	fmt.Fscanf(file, "%d", &n)
	/* START PART 2 */
	sn := n / 11
	/* END PART 2 START PART 1 */
	sn := n / 10
	/* END PART 1 */

	for i := 1; i <= n; i++ {
		if calc(i) >= sn {
			fmt.Println(i)
			break
		}
	}
}