import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
      	int result = 0;
      	for(int i=1;i<=num;i++){
          for(int j=1;j<=num;j++){
           // int tmp = gc.gcd(i,j);
            int tmp = gcd(i,j);
            for(int k=1;k<=num;k++){
         		//最初の2数の最大公約数を取得
              	result += gcd(tmp,k);
            }
          }
        }
      System.out.println(result);
    }
	static int gcd(int a,int b){
  		int tmp = 0;
  		int amari=-1;
  		if(a>=b){
    		tmp = a;
    		a = b;
  		}else{
    		tmp = b;
  		}

 		 while(amari != 0){
    		amari = a%tmp;
           	a = tmp;
           	tmp = amari;
  		 }
  		return a;
	}
}
/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