package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	sum := 0

	var gcd int
	for a := 1; a <= n; a++ {
		for b := a; b <= n; b++ {
			for c := b; c <= n; c++ {
				gcd = clacGcd(a, b, c)
				//fmt.Println(a, b, c, gcd)
				if a == b && b == c {
					sum += gcd
				} else if (a == b && b != c) || (a != b && b == c) {
					sum = sum + gcd*3
				} else {
					sum = sum + gcd*6
				}
				//fmt.Println(sum)
			}
		}
	}

	fmt.Println(sum)
}

func clacGcd(a int, b int, c int) int {
	var gcd int
	var tmp int
	for {
		if a%b != 0 {
			tmp = a % b
			a = b
			b = tmp
		} else {
			break
		}
	}
	for {
		if b%c != 0 {
			tmp = b % c
			b = c
			c = tmp
		} else {
			gcd = c
			break
		}
	}
	return gcd
}
