import java.util.*;
import java.math.*;
public class Main {
    
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	}
	
	//最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    }
} import java.util.*; util.* java import java.math.*; math.* java public class Main {
    
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	}
	
	//最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    }
} Main public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	} main {
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int res = 0; res 0 int gcd1 = 0; gcd1 0 int gcd2 = 0; gcd2 0 for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    } int i=1; int i=1; i 1 i<=a i a i++ i++ i {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    } {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    } for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        } int j=1; int j=1; j 1 j<=a j a j++ j++ j {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        } {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        } gcd1 = gcd(i, j) gcd1 gcd(i, j) gcd i j for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            } int k=1; int k=1; k 1 k<=a k a k++ k++ k {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            } {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            } gcd2 = gcd(gcd1, k) gcd2 gcd(gcd1, k) gcd gcd1 k res += gcd2 res gcd2 gcd1 = 0 gcd1 0 gcd2 = 0 gcd2 0 System.out.println(res) System.out.println System.out System System.out res String[] args args //最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    } gcd {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    } int r = 0; r 0 int a = 0; a 0 int b = 0; b 0 if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    } m >= n m n {
	        a = m;
	        b = n;
	    } a = m a m b = n b n {
	        a = n;
	        b = m;
	    } a = n a n b = m b m while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        } (r = a % b) != 0 (r = a % b) r a % b a b 0 {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        } if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            } r != a r a { 
                a = b;
                b = r;
            } a = b a b b = r b r {
                b = a;
            } b = a b a return b; b int m m int n n public class Main {
    
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	}
	
	//最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    }
} public class Main {
    
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	}
	
	//最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    }
} Main
import java.util.*;
import java.math.*;
public class Main {
    
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 入力
	int a = sc.nextInt();
	int res = 0;
	int gcd1 = 0;
	int gcd2 = 0;
    
    for(int i=1;i<=a;i++) {
        for(int j=1;j<=a;j++) {
            gcd1 = gcd(i, j);
            for(int k=1;k<=a;k++) {
                gcd2 = gcd(gcd1, k);
                res += gcd2;
            }
        }
        gcd1 = 0; //初期化
        gcd2 = 0; //初期化
    }
	// 出力
    System.out.println(res);
	}
	
	//最大公約数算出
	public static int gcd(int m, int n) {
	    int r = 0;
	    int a = 0;
	    int b = 0;
	    if(m >= n) {
	        a = m;
	        b = n;
	    } else {
	        a = n;
	        b = m;
	    }
        while( (r = a % b) != 0 ) {
            if(r != a) { 
                a = b;
                b = r;
            } else {
                b = a;
            }
        }
        return b;
    }
}