import java.util.Scanner;

/**
 * C - Sum of gcd of Tuples (Easy)
 * K∑a=1  K∑b=1  K∑c=1 gcd(a,b,c) を求めてください。
 * ただし、gcd(a,b,c) は a,b,c の最大公約数を表します。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    }

    /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    }

    /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    } main {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    } Scanner sc = new Scanner( System.in ); sc new Scanner( System.in ) long n = sc.nextLong(); n sc.nextLong() sc.nextLong sc long sum = 0; sum 0 for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        } {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        } long gcd1 = 0; gcd1 0 for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            } int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            } {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            } gcd1 = gcd( i, j ) gcd1 gcd( i, j ) gcd i j for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                } int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
                    sum += gcd( gcd1, k );
                } {
                    sum += gcd( gcd1, k );
                } sum += gcd( gcd1, k ) sum gcd( gcd1, k ) gcd gcd1 k System.out.println( sum ) System.out.println System.out System System.out sum sc.close() sc.close sc String[] args args /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    } gcd {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    } if( m < n ) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if( n == 0 ) return m; n == 0 n 0 return m; m return gcd( n, m % n ); gcd( n, m % n ) gcd n m % n m n long m m long n n public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    }

    /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    }

    /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    }
} Main
import java.util.Scanner;

/**
 * C - Sum of gcd of Tuples (Easy)
 * K∑a=1  K∑b=1  K∑c=1 gcd(a,b,c) を求めてください。
 * ただし、gcd(a,b,c) は a,b,c の最大公約数を表します。
 */
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        long n = sc.nextLong();

        long sum = 0;
        for( int i = 1; i <= n; i++ ) {
            long gcd1 = 0;
            for( int j = 1; j <= n; j++ ) {
                gcd1 = gcd( i, j );
                for( int k = 1; k <= n; k++ ) {
                    sum += gcd( gcd1, k );
                }
            }
        }

        System.out.println( sum );

        sc.close();
    }

    /*
     * 最大公約数を求める
     */
    private static long gcd( long m, long n ) {
        if( m < n ) return gcd(n, m);
        if( n == 0 ) return m;
        return gcd( n, m % n );
    }
}
