import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = Integer.parseInt(sc.next());
		
		long sum = 0;
		
		for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} 
		
		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.util.*; util.* java class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = Integer.parseInt(sc.next());
		
		long sum = 0;
		
		for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} 
		
		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) {
		Scanner sc = new Scanner(System.in);
		
		int k = Integer.parseInt(sc.next());
		
		long sum = 0;
		
		for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} 
		
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		
		int k = Integer.parseInt(sc.next());
		
		long sum = 0;
		
		for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} 
		
		System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k = Integer.parseInt(sc.next()); k Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc long sum = 0; sum 0 for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} int i = 1 ; int i = 1 ; i 1 i < k+1 i k+1 k 1 ++i ++i i {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    } int j = 1; int j = 1; j 1 j < k+1 j k+1 k 1 ++j ++j j {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    } {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    } for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        } int l = 1; int l = 1; l 1 l < k+1 l k+1 k 1 ++l ++l l {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        } {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        } int tmp = gcd(i, gcd(j, l)); tmp gcd(i, gcd(j, l)) gcd i gcd(j, l) gcd j l sum += tmp sum tmp 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
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = Integer.parseInt(sc.next());
		
		long sum = 0;
		
		for(int i = 1 ; i < k+1; ++i) {
		    for(int j = 1; j < k+1; ++j) {
		        for(int l = 1; l < k+1; ++l) {
		            int tmp = gcd(i, gcd(j, l));
		            sum += tmp;
		        }
		    }
		} 
		
		System.out.println(sum);
	}
	
	public static int gcd(int num1,int num2) {
    if(num2==0) return num1;
    else return gcd(num2,num1%num2);
	}
   
}