import java.util.*;
public class Main {
	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
	public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	}

} import java.util.*; util.* java public class Main {
	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
	public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	}

} Main public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } gcd {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } int r; r while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        } n > 0 n 0 {
            r = m % n;
            m = n;
            n = r;
        } r = m % n r m % n m n m = n m n n = r n r return m; m int m m int n n public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    } gcd {
		int r=gcd(m,n);
		return gcd(r,p);
       
    } int r=gcd(m,n); r gcd(m,n) gcd m n return gcd(r,p); gcd(r,p) gcd r p int m m int n n int p p public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	} main {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int t=0; t 0 for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		} int i=1; int i=1; i 1 i<=c i c i++ i++ i {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		} {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		} for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			} int j=1; int j=1; j 1 j<=c j c j++ j++ j {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			} {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			} for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				} int k=1; int k=1; k 1 k<=c k c k++ k++ k {
				t+=gcd(i,j,k);	
				} {
				t+=gcd(i,j,k);	
				} t+=gcd(i,j,k) t gcd(i,j,k) gcd i j k System.out.println(t) System.out.println System.out System System.out t String[] args args public class Main {
	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
	public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	}

} public class Main {
	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
	public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	}

} Main
import java.util.*;
public class Main {
	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
	public static int gcd(int m, int n,int p) {
		int r=gcd(m,n);
		return gcd(r,p);
       
    }

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int c = sc.nextInt();
		int t=0;
		for(int i=1;i<=c;i++) {
			for(int j=1;j<=c;j++) {
				for(int k=1;k<=c;k++) {
				t+=gcd(i,j,k);	
				}
			}
			
		}
		System.out.println(t);


	}

}
