import java.util.*;
public class Main
{
	
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    }
    
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
  
    // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } 
} import java.util.*; util.* java public class Main
{
	
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    }
    
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
  
    // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } 
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan long sum = 0; sum 0 for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        } {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        } for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	} {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	} for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		} int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		} {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		} sum += findGCD(new int[] {i, j, k} , 3) sum findGCD(new int[] {i, j, k} , 3) findGCD new int[] {i, j, k} 3 System.out.println(sum) System.out.println System.out System System.out sum String[] args args 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 // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } findGCD { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } int result = arr[0]; result arr[0] arr 0 for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); int i = 1; int i = 1; i 1 i < n i n i++ i++ i result = gcd(arr[i], result); result = gcd(arr[i], result) result gcd(arr[i], result) gcd arr[i] arr i result return result; result int arr[] arr int n n public class Main
{
	
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    }
    
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
  
    // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } 
} public class Main
{
	
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    }
    
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
  
    // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } 
} Main
import java.util.*;
public class Main
{
	
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
        	for (int j = 1; j <= n; j++) {
        		for (int k = 1; k <= n; k++) {
        			sum += findGCD(new int[] {i, j, k} , 3);
        		}
        	}
        }
        System.out.println(sum);
    }
    
    static int gcd(int a, int b) 
    { 
        if (a == 0) 
            return b; 
        return gcd(b % a, a); 
    } 
  
    // Function to find gcd of array of 
    // numbers 
    static int findGCD(int arr[], int n) 
    { 
        int result = arr[0]; 
        for (int i = 1; i < n; i++) 
            result = gcd(arr[i], result); 
  
        return result; 
    } 
}