import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main{
	static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } 
	
    public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    }
} import java.io.*; io.* java import java.math.*; math.* java import java.text.*; text.* java import java.util.*; util.* java import java.util.regex.*; regex.* java.util public class Main{
	static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } 
	
    public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    }
} Main static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } gcd { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } if (a == 0) 
            return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a int a a int b b static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } findGCD { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } int result = a; result a result = gcd(b,result) result gcd(b,result) gcd b result result = gcd(c,result) result gcd(c,result) gcd c result return result; result int a a int b b int c c public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    } main {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	} int i=1; int i=1; i 1 i<=k i k i++ i++ i {
        		for(int j=1;j<=k;j++) {
        			for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	} {
        		for(int j=1;j<=k;j++) {
        			for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	} for(int j=1;j<=k;j++) {
        			for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
        			for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	} {
        			for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	} for(int a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	} int a=1; int a=1; a 1 a<=k a k a++ a++ a {
                		sum+=findGCD(i,j,a);
                	} {
                		sum+=findGCD(i,j,a);
                	} sum+=findGCD(i,j,a) sum findGCD(i,j,a) findGCD i j a System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{
	static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } 
	
    public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    }
} public class Main{
	static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } 
	
    public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    }
} Main
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main{
	static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
	
	static int findGCD(int a,int b,int c) 
    { 
        int result = a; 
        result = gcd(b,result);
        result = gcd(c,result);
        return result; 
    } 
	
    public static void main(String[] args) throws IOException {
        	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 a=1;a<=k;a++) {
                		sum+=findGCD(i,j,a);
                	}
            	}
        	}
        	System.out.println(sum);
    }
}
