import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		
		long total = 0;
		
		for(int a = 1; a < k+1; a++) {
			for(int b = 1; b < k+1; b++) {
				for(int c = 1; c < k+1; c++) {
					total += gcd(gcd(a, b), c);
				}
			}
		}
		System.out.println(total);
	}
	
	//ユークリッドの互除法
	static int gcd(int p, int q) {
		if(p % q == 0)	return q;	//最大公約数
		return gcd(q, p % q);		//答えが見つかるまで繰り返し
	}

}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz