コード例 #1
0
ファイル: Problem075.go プロジェクト: rif/golang-stuff
func main() {
	starttime := time.Now()

	max := 1500000

	set := make(map[int]int)

	for m := 1; (2*m*m)+(2*m) < max; m++ {

		for n := m%2 + 1; n < m; n += 2 {
			if euler.GCD(int64(m), int64(n)) == 1 && (m-n)%2 == 1 {
				for k := 1; k*((2*m*m)+(2*m*n)) < max; k++ {
					set[k*((2*m*m)+(2*m*n))]++

				}

			}

		}

	}

	total := 0
	for _, sum := range set {
		if sum == 1 {
			total++
		}
	}
	fmt.Println(total)

	fmt.Println("Elapsed time:", time.Since(starttime))

}
コード例 #2
0
func routes(M int) (total int) {

	maxm := M //could be more clever

	for n := 1; n < maxm; n++ {

		for m := n + 1; m < maxm; m += 2 {

			if euler.GCD(int64(m), int64(n)) == 1 {

				a := m*m - n*n
				b := 2 * m * n
				a, b = sort(a, b)

				//a is two sides case
				for k := 1; k*b <= M; k++ {
					total += (a * k) / 2
				}

				//b is two sides case
				if 2*a >= b {
					for k := 1; k*a <= M; k++ {
						total += ((2 * a * k) - (b * k) + 2) / 2
					}
				}
			}

		}

	}
	return
}