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