import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	var sum = 0L
	for (a in 1..k){
		for(b in a..k){
			val ab = gcd(b, a)
			for (c in b..k){
				val t = when{
					a==c -> 1
					a==b || b==c -> 3
					else -> 6
				}
				sum += t*gcd(ab, c)
			}
		}
	}
	println(sum)
}

fun gcd(a: Int, b: Int): Int{
	var a = a; var b = b
	if (a<b) {
		val tmp = a; a = b; b = tmp
	}
	if (a%b==0) return b
	else return gcd(b, a%b)
}
