import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    }

    public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    }

    public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

} Main public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    } main {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc int sum = 0; sum 0 for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	} int i=1; int i=1; i 1 i<=K i K i++ i++ i {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	} {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	} for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		} int j=1; int j=1; j 1 j<=K j K j++ j++ j {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		} {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		} for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			} int k=1; int k=1; k 1 k<=K k K k++ k++ k {
    				sum += gcd(i,gcd(j,k));
    			} {
    				sum += gcd(i,gcd(j,k));
    			} sum += gcd(i,gcd(j,k)) sum gcd(i,gcd(j,k)) gcd i gcd(j,k) gcd j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    } gcd {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    } if(num2==0) return num1;
        else return gcd(num2,num1%num2); num2==0 num2 0 return num1; num1 return gcd(num2,num1%num2); gcd(num2,num1%num2) gcd num2 num1%num2 num1 num2 int num1 num1 int num2 num2 public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    }

    public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

} public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    }

    public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int K = sc.nextInt();

    	int sum = 0;

    	for(int i=1;i<=K;i++) {
    		for(int j=1;j<=K;j++) {
    			for(int k=1;k<=K;k++) {
    				sum += gcd(i,gcd(j,k));
    			}
    		}
    	}
    	System.out.println(sum);

    }

    public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }

}
